1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 19:47:24 +08:00
osu-lazer/osu.Game/Screens/Play/PauseOverlay.cs

225 lines
8.8 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 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.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Play.Pause;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
2017-01-27 17:24:49 +08:00
namespace osu.Game.Screens.Play
{
public class PauseOverlay : OverlayContainer
{
private const int transition_duration = 200;
private const int button_height = 70;
private const float background_alpha = 0.75f;
protected override bool HideOnEscape => false;
public Action OnResume;
public Action OnRetry;
public Action OnQuit;
public int Retries
{
set
{
2017-01-31 21:17:47 +08:00
if (retryCounterContainer != null)
{
// "You've retried 1,065 times in this session"
// "You've retried 1 time in this session"
2017-01-31 21:17:47 +08:00
retryCounterContainer.Children = new Drawable[]
{
new OsuSpriteText
{
Text = "You've retried ",
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f),
TextSize = 18
},
new OsuSpriteText
{
2017-03-09 13:24:16 +08:00
Text = $"{value:n0}",
Font = @"Exo2.0-Bold",
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f),
TextSize = 18
},
new OsuSpriteText
{
2017-03-07 09:59:19 +08:00
Text = $" time{(value == 1 ? "" : "s")} in this session",
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f),
TextSize = 18
2017-01-31 21:17:47 +08:00
}
};
}
}
}
2017-03-02 02:33:01 +08:00
private FillFlowContainer retryCounterContainer;
public override bool HandleInput => State == Visibility.Visible;
protected override void PopIn() => FadeIn(transition_duration, EasingTypes.In);
protected override void PopOut() => FadeOut(transition_duration, EasingTypes.In);
// Don't let mouse down events through the overlay or people can click circles while paused.
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true;
2017-03-16 21:50:16 +08:00
protected override bool OnMouseMove(InputState state) => true;
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (args.Key == Key.Escape)
{
2017-01-31 21:17:47 +08:00
if (State == Visibility.Hidden) return false;
resume();
return true;
}
return base.OnKeyDown(state, args);
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
2017-01-28 02:18:57 +08:00
{
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
Alpha = background_alpha,
},
2017-03-02 02:33:01 +08:00
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2017-03-04 18:00:17 +08:00
Direction = FillDirection.Vertical,
2017-03-02 02:33:01 +08:00
Spacing = new Vector2(0, 50),
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Children = new Drawable[]
{
2017-03-02 02:33:01 +08:00
new FillFlowContainer
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 20),
Children = new Drawable[]
{
new OsuSpriteText
{
Text = @"paused",
Font = @"Exo2.0-Medium",
Spacing = new Vector2(5, 0),
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
TextSize = 30,
Colour = colours.Yellow,
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f)
},
new OsuSpriteText
{
Text = @"you're not going to do what i think you're going to do, are ya?",
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.25f)
}
}
},
2017-03-02 02:33:01 +08:00
new FillFlowContainer
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Masking = true,
EdgeEffect = new EdgeEffect
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.6f),
Radius = 50
},
Children = new Drawable[]
{
new ResumeButton
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Height = button_height,
Action = resume
},
new RetryButton
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Height = button_height,
Action = delegate
{
OnRetry?.Invoke();
Hide();
}
},
new QuitButton
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Height = button_height,
Action = delegate
{
OnQuit?.Invoke();
Hide();
}
}
}
},
2017-03-02 02:33:01 +08:00
retryCounterContainer = new FillFlowContainer
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
}
}
},
new PauseProgressBar
{
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
Width = 1f
}
};
2017-01-31 21:17:47 +08:00
Retries = 0;
}
private void resume()
{
OnResume?.Invoke();
Hide();
}
2017-01-27 17:24:49 +08:00
public PauseOverlay()
{
AlwaysReceiveInput = true;
2017-01-27 17:24:49 +08:00
RelativeSizeAxes = Axes.Both;
}
}
}