2018-01-05 11:21:19 +00:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-02-07 04:59:30 +00:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2017-01-27 12:57:22 +00:00
|
|
|
|
|
2017-05-19 12:54:14 +00:00
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework;
|
2017-01-27 12:57:22 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
2017-05-19 12:54:14 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-02-22 12:28:40 +00:00
|
|
|
|
using osu.Framework.Input;
|
2017-05-19 12:54:14 +00:00
|
|
|
|
using osu.Framework.Threading;
|
2017-05-19 09:18:21 +00:00
|
|
|
|
using osu.Framework.Timing;
|
2017-01-27 12:57:22 +00:00
|
|
|
|
using osu.Game.Graphics;
|
2017-05-19 12:54:14 +00:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Screens.Ranking;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-06-20 05:54:23 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-06-27 12:05:49 +00:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-01-08 17:21:18 +00:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
|
using osu.Game.Input.Bindings;
|
2017-01-27 12:57:22 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
2018-03-05 15:10:53 +00:00
|
|
|
|
public class SkipOverlay : OverlayContainer, IKeyBindingHandler<GlobalAction>
|
2017-01-27 12:57:22 +00:00
|
|
|
|
{
|
2017-05-19 09:18:21 +00:00
|
|
|
|
private readonly double startTime;
|
2018-02-27 07:01:30 +00:00
|
|
|
|
|
2018-02-27 07:10:12 +00:00
|
|
|
|
public IAdjustableClock AdjustableClock;
|
2018-02-27 07:01:30 +00:00
|
|
|
|
public IFrameBasedClock FramedClock;
|
2017-05-19 09:18:21 +00:00
|
|
|
|
|
2017-05-19 12:54:14 +00:00
|
|
|
|
private Button button;
|
|
|
|
|
private Box remainingTimeBox;
|
|
|
|
|
|
|
|
|
|
private FadeContainer fadeContainer;
|
|
|
|
|
private double displayTime;
|
|
|
|
|
|
2018-02-06 05:29:03 +00:00
|
|
|
|
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true;
|
2018-03-05 15:27:55 +00:00
|
|
|
|
protected override bool BlockPassThroughMouse => false;
|
2018-03-05 10:43:33 +00:00
|
|
|
|
|
2018-03-05 15:10:53 +00:00
|
|
|
|
public SkipOverlay(double startTime)
|
2017-01-27 12:57:22 +00:00
|
|
|
|
{
|
2017-05-19 09:18:21 +00:00
|
|
|
|
this.startTime = startTime;
|
2017-05-19 12:54:14 +00:00
|
|
|
|
|
2018-01-12 09:21:17 +00:00
|
|
|
|
State = Visibility.Visible;
|
|
|
|
|
|
2017-05-19 12:54:14 +00:00
|
|
|
|
RelativePositionAxes = Axes.Both;
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Position = new Vector2(0.5f, 0.7f);
|
|
|
|
|
Size = new Vector2(1, 0.14f);
|
|
|
|
|
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseMove(InputState state)
|
|
|
|
|
{
|
|
|
|
|
fadeContainer.State = Visibility.Visible;
|
|
|
|
|
return base.OnMouseMove(state);
|
2017-01-27 12:57:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2017-05-19 12:54:14 +00:00
|
|
|
|
private void load(OsuColour colours)
|
2017-01-27 12:57:22 +00:00
|
|
|
|
{
|
2017-05-19 13:12:09 +00:00
|
|
|
|
var baseClock = Clock;
|
|
|
|
|
|
2018-02-27 07:01:30 +00:00
|
|
|
|
if (FramedClock != null)
|
2018-02-27 08:23:12 +00:00
|
|
|
|
{
|
2018-02-27 07:01:30 +00:00
|
|
|
|
Clock = FramedClock;
|
2018-02-28 12:50:52 +00:00
|
|
|
|
ProcessCustomClock = false;
|
2018-02-27 08:23:12 +00:00
|
|
|
|
}
|
2017-05-19 13:12:09 +00:00
|
|
|
|
|
2017-05-19 12:54:14 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
fadeContainer = new FadeContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
button = new Button
|
|
|
|
|
{
|
2017-05-19 13:12:09 +00:00
|
|
|
|
Clock = baseClock,
|
2017-05-19 12:54:14 +00:00
|
|
|
|
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 skip_required_cutoff = 3000;
|
|
|
|
|
private const double fade_time = 300;
|
2017-05-19 09:18:21 +00:00
|
|
|
|
|
2017-05-19 12:54:14 +00:00
|
|
|
|
private double beginFadeTime => startTime - skip_required_cutoff - fade_time;
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2017-05-19 09:18:21 +00:00
|
|
|
|
|
|
|
|
|
if (startTime < skip_required_cutoff)
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0;
|
|
|
|
|
Expire();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-14 16:18:12 +00:00
|
|
|
|
this.FadeInFromZero(fade_time);
|
2017-05-19 12:54:14 +00:00
|
|
|
|
using (BeginAbsoluteSequence(beginFadeTime))
|
2017-07-14 16:18:12 +00:00
|
|
|
|
this.FadeOut(fade_time);
|
2017-05-19 12:54:14 +00:00
|
|
|
|
|
2018-02-27 07:10:12 +00:00
|
|
|
|
button.Action = () => AdjustableClock?.Seek(startTime - skip_required_cutoff - fade_time);
|
2017-05-19 09:18:21 +00:00
|
|
|
|
|
2017-05-19 12:54:14 +00:00
|
|
|
|
displayTime = Time.Current;
|
2017-05-19 09:18:21 +00:00
|
|
|
|
|
|
|
|
|
Expire();
|
2017-01-27 12:57:22 +00:00
|
|
|
|
}
|
2017-02-22 12:28:40 +00:00
|
|
|
|
|
2018-01-12 09:21:17 +00:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
this.FadeIn();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
this.FadeOut();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 12:54:14 +00:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2017-07-22 18:50:25 +00:00
|
|
|
|
remainingTimeBox.ResizeWidthTo((float)Math.Max(0, 1 - (Time.Current - displayTime) / (beginFadeTime - displayTime)), 120, Easing.OutQuint);
|
2017-05-19 12:54:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 17:21:18 +00:00
|
|
|
|
public bool OnPressed(GlobalAction action)
|
2017-02-22 12:28:40 +00:00
|
|
|
|
{
|
2018-01-08 17:21:18 +00:00
|
|
|
|
switch (action)
|
2017-02-22 12:28:40 +00:00
|
|
|
|
{
|
2018-01-08 17:21:18 +00:00
|
|
|
|
case GlobalAction.SkipCutscene:
|
2017-05-28 09:34:12 +00:00
|
|
|
|
button.TriggerOnClick();
|
2017-02-22 12:28:40 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 17:21:18 +00:00
|
|
|
|
return false;
|
2017-02-22 12:28:40 +00:00
|
|
|
|
}
|
2017-05-19 12:54:14 +00:00
|
|
|
|
|
2018-01-08 17:21:18 +00:00
|
|
|
|
public bool OnReleased(GlobalAction action) => false;
|
|
|
|
|
|
2017-05-19 12:54:14 +00:00
|
|
|
|
private class FadeContainer : Container, IStateful<Visibility>
|
|
|
|
|
{
|
2017-09-04 00:10:04 +00:00
|
|
|
|
public event Action<Visibility> StateChanged;
|
|
|
|
|
|
2017-05-19 12:54:14 +00:00
|
|
|
|
private Visibility state;
|
|
|
|
|
private ScheduledDelegate scheduledHide;
|
|
|
|
|
|
|
|
|
|
public Visibility State
|
|
|
|
|
{
|
2018-02-06 05:30:01 +00:00
|
|
|
|
get { return state; }
|
2017-05-19 12:54:14 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2018-02-06 05:30:01 +00:00
|
|
|
|
bool stateChanged = value != state;
|
2017-05-19 12:54:14 +00:00
|
|
|
|
|
|
|
|
|
state = value;
|
|
|
|
|
|
|
|
|
|
scheduledHide?.Cancel();
|
|
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case Visibility.Visible:
|
2018-02-06 05:30:01 +00:00
|
|
|
|
// we may be triggered to become visible mnultiple times but we only want to transform once.
|
|
|
|
|
if (stateChanged)
|
2017-07-22 18:50:25 +00:00
|
|
|
|
this.FadeIn(500, Easing.OutExpo);
|
2017-05-19 12:54:14 +00:00
|
|
|
|
|
2017-07-07 05:59:17 +00:00
|
|
|
|
if (!IsHovered)
|
2017-05-19 12:54:14 +00:00
|
|
|
|
using (BeginDelayedSequence(1000))
|
|
|
|
|
scheduledHide = Schedule(() => State = Visibility.Hidden);
|
|
|
|
|
break;
|
|
|
|
|
case Visibility.Hidden:
|
2017-07-22 18:50:25 +00:00
|
|
|
|
this.FadeOut(1000, Easing.OutExpo);
|
2017-05-19 12:54:14 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-09-04 00:10:04 +00:00
|
|
|
|
|
|
|
|
|
StateChanged?.Invoke(State);
|
2017-05-19 12:54:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
State = Visibility.Visible;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-27 12:05:49 +00:00
|
|
|
|
private class Button : OsuClickableContainer
|
2017-05-19 12:54:14 +00:00
|
|
|
|
{
|
|
|
|
|
private Color4 colourNormal;
|
|
|
|
|
private Color4 colourHover;
|
|
|
|
|
private Box box;
|
|
|
|
|
private FillFlowContainer flow;
|
|
|
|
|
private Box background;
|
|
|
|
|
private AspectContainer aspect;
|
|
|
|
|
|
|
|
|
|
public Button()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2017-06-29 19:05:37 +00:00
|
|
|
|
private void load(OsuColour colours)
|
2017-05-19 12:54:14 +00:00
|
|
|
|
{
|
|
|
|
|
colourNormal = colours.Yellow;
|
|
|
|
|
colourHover = colours.YellowDark;
|
|
|
|
|
|
|
|
|
|
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,
|
2017-06-08 07:27:35 +00:00
|
|
|
|
Children = new[]
|
2017-05-19 12:54:14 +00:00
|
|
|
|
{
|
2017-08-15 00:30:46 +00:00
|
|
|
|
new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.fa_chevron_right },
|
|
|
|
|
new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.fa_chevron_right },
|
|
|
|
|
new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.fa_chevron_right },
|
2017-05-19 12:54:14 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
RelativePositionAxes = Axes.Y,
|
|
|
|
|
Y = 0.7f,
|
|
|
|
|
TextSize = 12,
|
|
|
|
|
Font = @"Exo2.0-Bold",
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Text = @"SKIP",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
2017-07-22 18:50:25 +00:00
|
|
|
|
flow.TransformSpacingTo(new Vector2(5), 500, Easing.OutQuint);
|
|
|
|
|
box.FadeColour(colourHover, 500, Easing.OutQuint);
|
|
|
|
|
background.FadeTo(0.4f, 500, Easing.OutQuint);
|
2018-03-05 15:27:55 +00:00
|
|
|
|
return true;
|
2017-05-19 12:54:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
2017-07-22 18:50:25 +00:00
|
|
|
|
flow.TransformSpacingTo(new Vector2(0), 500, Easing.OutQuint);
|
|
|
|
|
box.FadeColour(colourNormal, 500, Easing.OutQuint);
|
|
|
|
|
background.FadeTo(0.2f, 500, Easing.OutQuint);
|
2017-05-19 12:54:14 +00:00
|
|
|
|
base.OnHoverLost(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
|
|
|
|
{
|
2017-07-22 18:50:25 +00:00
|
|
|
|
aspect.ScaleTo(0.75f, 2000, Easing.OutQuint);
|
2017-05-19 12:54:14 +00:00
|
|
|
|
return base.OnMouseDown(state, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
|
|
|
|
{
|
2017-07-22 18:50:25 +00:00
|
|
|
|
aspect.ScaleTo(1, 1000, Easing.OutElastic);
|
2017-05-19 12:54:14 +00:00
|
|
|
|
return base.OnMouseUp(state, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(InputState state)
|
|
|
|
|
{
|
2017-07-13 21:35:19 +00:00
|
|
|
|
if (!Enabled)
|
2017-07-13 19:59:17 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2017-07-22 18:50:25 +00:00
|
|
|
|
box.FlashColour(Color4.White, 500, Easing.OutQuint);
|
|
|
|
|
aspect.ScaleTo(1.2f, 2000, Easing.OutQuint);
|
2017-07-13 21:35:19 +00:00
|
|
|
|
|
|
|
|
|
bool result = base.OnClick(state);
|
2017-07-14 00:39:40 +00:00
|
|
|
|
|
|
|
|
|
// for now, let's disable the skip button after the first press.
|
|
|
|
|
// this will likely need to be contextual in the future (bound from external components).
|
2017-07-13 21:35:19 +00:00
|
|
|
|
Enabled.Value = false;
|
|
|
|
|
|
|
|
|
|
return result;
|
2017-05-19 12:54:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-27 12:57:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|