1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-09 09:37:42 +08:00
osu-lazer/osu.Game.Rulesets.Osu/UI/OsuResumeOverlay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

126 lines
3.8 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2019-03-19 18:04:07 +08:00
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2019-03-19 18:04:07 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Osu.UI.Cursor;
using osu.Game.Screens.Play;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.UI
{
public class OsuResumeOverlay : ResumeOverlay
{
private Container cursorScaleContainer;
2019-03-19 18:04:07 +08:00
private OsuClickToResumeCursor clickToResumeCursor;
2019-10-14 16:13:36 +08:00
private OsuCursorContainer localCursorContainer;
private IBindable<float> localCursorScale;
2019-03-19 18:04:07 +08:00
public override CursorContainer LocalCursor => State.Value == Visibility.Visible ? localCursorContainer : null;
2019-03-19 18:04:07 +08:00
protected override string Message => "Click the orange cursor to resume";
[BackgroundDependencyLoader]
2019-03-25 14:30:51 +08:00
private void load()
2019-03-19 18:04:07 +08:00
{
Add(cursorScaleContainer = new Container
{
Child = clickToResumeCursor = new OsuClickToResumeCursor { ResumeRequested = Resume }
});
2019-03-19 18:04:07 +08:00
}
2019-11-01 13:50:38 +08:00
protected override void PopIn()
2019-03-19 18:04:07 +08:00
{
2019-11-01 13:50:38 +08:00
base.PopIn();
GameplayCursor.ActiveCursor.Hide();
cursorScaleContainer.Position = ToLocalSpace(GameplayCursor.ActiveCursor.ScreenSpaceDrawQuad.Centre);
clickToResumeCursor.Appear();
2019-03-25 18:21:34 +08:00
if (localCursorContainer == null)
{
2019-10-14 16:13:36 +08:00
Add(localCursorContainer = new OsuCursorContainer());
localCursorScale = new BindableFloat();
localCursorScale.BindTo(localCursorContainer.CursorScale);
localCursorScale.BindValueChanged(scale => cursorScaleContainer.Scale = new Vector2(scale.NewValue), true);
}
2019-03-19 18:04:07 +08:00
}
2019-11-01 13:50:38 +08:00
protected override void PopOut()
2019-03-19 18:04:07 +08:00
{
2019-11-01 13:50:38 +08:00
base.PopOut();
2019-03-25 18:21:34 +08:00
localCursorContainer?.Expire();
localCursorContainer = null;
2019-11-01 14:33:38 +08:00
GameplayCursor?.ActiveCursor?.Show();
2019-03-19 18:04:07 +08:00
}
protected override bool OnHover(HoverEvent e) => true;
public class OsuClickToResumeCursor : OsuCursor, IKeyBindingHandler<OsuAction>
{
public override bool HandlePositionalInput => true;
public Action ResumeRequested;
public OsuClickToResumeCursor()
{
RelativePositionAxes = Axes.Both;
}
protected override bool OnHover(HoverEvent e)
{
updateColour();
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
updateColour();
base.OnHoverLost(e);
}
2021-09-16 17:26:12 +08:00
public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
2019-03-19 18:04:07 +08:00
{
2021-09-16 17:26:12 +08:00
switch (e.Action)
2019-03-19 18:04:07 +08:00
{
case OsuAction.LeftButton:
case OsuAction.RightButton:
if (!IsHovered) return false;
this.ScaleTo(2, TRANSITION_TIME, Easing.OutQuint);
2019-03-19 18:04:07 +08:00
ResumeRequested?.Invoke();
return true;
}
return false;
}
2021-09-16 17:26:12 +08:00
public void OnReleased(KeyBindingReleaseEvent<OsuAction> e)
{
}
2019-03-19 18:04:07 +08:00
public void Appear() => Schedule(() =>
2019-03-19 18:04:07 +08:00
{
updateColour();
this.ScaleTo(4).Then().ScaleTo(1, 1000, Easing.OutQuint);
2019-03-19 18:04:07 +08:00
});
private void updateColour()
{
this.FadeColour(IsHovered ? Color4.White : Color4.Orange, 400, Easing.OutQuint);
}
}
}
}