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
|
|
|
|
|
2017-03-28 17:09:26 +08:00
|
|
|
|
using System;
|
2021-07-06 01:22:55 +08:00
|
|
|
|
using System.Collections.Generic;
|
2021-07-07 18:59:31 +08:00
|
|
|
|
using System.Linq;
|
2021-07-06 01:22:55 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-03-28 17:09:26 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-07-06 01:22:55 +08:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-06-09 15:28:02 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2023-05-27 18:29:14 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2023-05-25 16:38:35 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2021-07-06 01:22:55 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-06-09 15:28:02 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2021-07-06 01:22:55 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2023-05-27 18:47:05 +08:00
|
|
|
|
using osu.Game.Localisation;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-28 17:09:26 +08:00
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
2018-06-09 15:28:02 +08:00
|
|
|
|
public abstract partial class GameplayMenuOverlay : OverlayContainer, IKeyBindingHandler<GlobalAction>
|
2017-03-28 17:09:26 +08:00
|
|
|
|
{
|
2020-07-17 18:08:50 +08:00
|
|
|
|
protected const int TRANSITION_DURATION = 200;
|
|
|
|
|
|
2017-03-28 17:09:26 +08:00
|
|
|
|
private const int button_height = 70;
|
|
|
|
|
private const float background_alpha = 0.75f;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-09-26 13:01:15 +08:00
|
|
|
|
protected override bool BlockNonPositionalInput => true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-04-12 15:41:36 +08:00
|
|
|
|
protected override bool BlockScrollInput => false;
|
|
|
|
|
|
2018-09-26 13:01:15 +08:00
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-02-28 14:42:36 +08:00
|
|
|
|
public Action? OnResume { get; init; }
|
|
|
|
|
public Action? OnRetry { get; init; }
|
|
|
|
|
public Action? OnQuit { get; init; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-06-09 15:28:02 +08:00
|
|
|
|
/// <summary>
|
2018-06-27 11:57:26 +08:00
|
|
|
|
/// Action that is invoked when <see cref="GlobalAction.Back"/> is triggered.
|
2018-06-09 15:28:02 +08:00
|
|
|
|
/// </summary>
|
2023-12-28 19:13:19 +08:00
|
|
|
|
protected virtual Action BackAction => () =>
|
|
|
|
|
{
|
|
|
|
|
// We prefer triggering the button click as it will animate...
|
|
|
|
|
// but sometimes buttons aren't present (see FailOverlay's constructor as an example).
|
|
|
|
|
if (Buttons.Any())
|
|
|
|
|
Buttons.Last().TriggerClick();
|
|
|
|
|
else
|
|
|
|
|
OnQuit?.Invoke();
|
|
|
|
|
};
|
2018-06-09 15:28:02 +08:00
|
|
|
|
|
2019-01-28 02:19:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Action that is invoked when <see cref="GlobalAction.Select"/> is triggered.
|
|
|
|
|
/// </summary>
|
2021-08-04 16:27:44 +08:00
|
|
|
|
protected virtual Action SelectAction => () => InternalButtons.Selected?.TriggerClick();
|
2019-03-24 11:03:06 +08:00
|
|
|
|
|
2023-05-27 18:29:14 +08:00
|
|
|
|
public abstract LocalisableString Header { get; }
|
2019-03-24 11:03:06 +08:00
|
|
|
|
|
2023-05-24 16:58:48 +08:00
|
|
|
|
protected SelectionCycleFillFlowContainer<DialogButton> InternalButtons = null!;
|
2017-12-18 18:13:08 +08:00
|
|
|
|
public IReadOnlyList<DialogButton> Buttons => InternalButtons;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-05-24 16:58:48 +08:00
|
|
|
|
private TextFlowContainer playInfoText = null!;
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private GlobalActionContainer globalAction { get; set; } = null!;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-18 15:40:50 +08:00
|
|
|
|
protected GameplayMenuOverlay()
|
2017-03-28 17:09:26 +08:00
|
|
|
|
{
|
2017-12-18 13:05:12 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2017-03-28 17:09:26 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-28 17:09:26 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Black,
|
|
|
|
|
Alpha = background_alpha,
|
|
|
|
|
},
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Spacing = new Vector2(0, 50),
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2023-05-24 16:58:48 +08:00
|
|
|
|
new OsuSpriteText
|
2017-03-28 17:09:26 +08:00
|
|
|
|
{
|
2023-05-24 16:58:48 +08:00
|
|
|
|
Text = Header,
|
|
|
|
|
Font = OsuFont.GetFont(size: 48),
|
2017-03-28 17:09:26 +08:00
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
2023-05-24 16:58:48 +08:00
|
|
|
|
Colour = colours.Yellow,
|
2017-03-28 17:09:26 +08:00
|
|
|
|
},
|
2021-07-06 01:22:55 +08:00
|
|
|
|
InternalButtons = new SelectionCycleFillFlowContainer<DialogButton>
|
2017-03-28 17:09:26 +08:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Masking = true,
|
2017-06-12 11:48:47 +08:00
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
2017-03-28 17:09:26 +08:00
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.6f),
|
|
|
|
|
Radius = 50
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-05-24 16:58:48 +08:00
|
|
|
|
playInfoText = new OsuTextFlowContainer(cp => cp.Font = OsuFont.GetFont(size: 18))
|
2017-03-28 17:09:26 +08:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
2023-05-24 16:58:48 +08:00
|
|
|
|
TextAnchor = Anchor.TopCentre,
|
2017-03-28 17:09:26 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-02-28 14:41:49 +08:00
|
|
|
|
if (OnResume != null)
|
|
|
|
|
AddButton(GameplayMenuOverlayStrings.Continue, colours.Green, () => OnResume.Invoke());
|
|
|
|
|
|
|
|
|
|
if (OnRetry != null)
|
|
|
|
|
AddButton(GameplayMenuOverlayStrings.Retry, colours.YellowDark, () => OnRetry.Invoke());
|
|
|
|
|
|
|
|
|
|
if (OnQuit != null)
|
|
|
|
|
AddButton(GameplayMenuOverlayStrings.Quit, new Color4(170, 27, 39, 255), () => OnQuit.Invoke());
|
|
|
|
|
|
2022-06-24 20:25:23 +08:00
|
|
|
|
State.ValueChanged += _ => InternalButtons.Deselect();
|
2021-08-05 12:24:59 +08:00
|
|
|
|
|
2023-05-24 17:09:19 +08:00
|
|
|
|
updateInfoText();
|
2017-03-28 17:09:26 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-18 23:53:17 +08:00
|
|
|
|
private int retries;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-18 13:05:12 +08:00
|
|
|
|
public int Retries
|
2017-03-28 17:09:26 +08:00
|
|
|
|
{
|
2017-12-18 13:05:12 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-12-18 23:53:17 +08:00
|
|
|
|
if (value == retries)
|
|
|
|
|
return;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-18 23:53:17 +08:00
|
|
|
|
retries = value;
|
2023-05-24 16:58:48 +08:00
|
|
|
|
|
|
|
|
|
if (IsLoaded)
|
2023-05-24 17:09:19 +08:00
|
|
|
|
updateInfoText();
|
2017-12-18 13:05:12 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-05-24 17:09:19 +08:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
this.FadeIn(TRANSITION_DURATION, Easing.In);
|
|
|
|
|
updateInfoText();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-17 18:08:50 +08:00
|
|
|
|
protected override void PopOut() => this.FadeOut(TRANSITION_DURATION, Easing.In);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-18 13:05:12 +08:00
|
|
|
|
// Don't let mouse down events through the overlay or people can click circles while paused.
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e) => true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnMouseMove(MouseMoveEvent e) => true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-05-27 18:29:14 +08:00
|
|
|
|
protected void AddButton(LocalisableString text, Color4 colour, Action? action)
|
2017-12-18 13:05:12 +08:00
|
|
|
|
{
|
2017-12-18 15:40:50 +08:00
|
|
|
|
var button = new Button
|
2017-12-18 13:05:12 +08:00
|
|
|
|
{
|
|
|
|
|
Text = text,
|
|
|
|
|
ButtonColour = colour,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Height = button_height,
|
|
|
|
|
Action = delegate
|
|
|
|
|
{
|
|
|
|
|
action?.Invoke();
|
|
|
|
|
Hide();
|
|
|
|
|
}
|
2017-12-18 15:29:40 +08:00
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-18 18:13:08 +08:00
|
|
|
|
InternalButtons.Add(button);
|
2017-12-18 15:29:40 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-01-09 06:08:36 +08:00
|
|
|
|
public virtual bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2018-06-09 15:28:02 +08:00
|
|
|
|
{
|
2021-09-16 17:26:12 +08:00
|
|
|
|
switch (e.Action)
|
2019-01-28 02:19:20 +08:00
|
|
|
|
{
|
2020-03-02 17:55:28 +08:00
|
|
|
|
case GlobalAction.SelectPrevious:
|
2020-08-15 19:36:00 +08:00
|
|
|
|
InternalButtons.SelectPrevious();
|
2020-03-02 17:55:28 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case GlobalAction.SelectNext:
|
2020-08-15 19:36:00 +08:00
|
|
|
|
InternalButtons.SelectNext();
|
2020-03-02 17:55:28 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
2019-03-24 11:03:06 +08:00
|
|
|
|
case GlobalAction.Back:
|
|
|
|
|
BackAction.Invoke();
|
|
|
|
|
return true;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2019-03-24 11:03:06 +08:00
|
|
|
|
case GlobalAction.Select:
|
|
|
|
|
SelectAction.Invoke();
|
|
|
|
|
return true;
|
2019-01-28 02:19:20 +08:00
|
|
|
|
}
|
2019-03-24 11:19:09 +08:00
|
|
|
|
|
|
|
|
|
return false;
|
2018-06-09 15:28:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
2019-03-24 11:19:09 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
2021-07-06 20:11:46 +08:00
|
|
|
|
|
2023-05-24 17:09:19 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private IGameplayClock? gameplayClock { get; set; }
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
2023-05-25 16:38:35 +08:00
|
|
|
|
private GameplayState? gameplayState { get; set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-05-24 17:09:19 +08:00
|
|
|
|
private void updateInfoText()
|
|
|
|
|
{
|
2023-05-24 16:58:48 +08:00
|
|
|
|
playInfoText.Clear();
|
2023-05-27 18:47:05 +08:00
|
|
|
|
playInfoText.AddText(GameplayMenuOverlayStrings.RetryCount);
|
2023-05-24 16:58:48 +08:00
|
|
|
|
playInfoText.AddText(retries.ToString(), cp => cp.Font = cp.Font.With(weight: FontWeight.Bold));
|
2023-05-24 17:09:19 +08:00
|
|
|
|
|
2023-05-26 19:39:22 +08:00
|
|
|
|
if (getSongProgress() is int progress)
|
2023-05-24 17:09:19 +08:00
|
|
|
|
{
|
|
|
|
|
playInfoText.NewLine();
|
2023-05-27 18:47:05 +08:00
|
|
|
|
playInfoText.AddText(GameplayMenuOverlayStrings.SongProgress);
|
2023-05-26 19:39:22 +08:00
|
|
|
|
playInfoText.AddText($"{progress}%", cp => cp.Font = cp.Font.With(weight: FontWeight.Bold));
|
2023-05-24 17:09:19 +08:00
|
|
|
|
}
|
2017-12-18 23:53:17 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-05-26 19:39:22 +08:00
|
|
|
|
private int? getSongProgress()
|
|
|
|
|
{
|
|
|
|
|
if (gameplayClock == null || gameplayState == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
(double firstHitTime, double lastHitTime) = gameplayState.Beatmap.CalculatePlayableBounds();
|
|
|
|
|
|
|
|
|
|
double playableLength = (lastHitTime - firstHitTime);
|
|
|
|
|
|
|
|
|
|
if (playableLength == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return (int)Math.Clamp(((gameplayClock.CurrentTime - firstHitTime) / playableLength) * 100, 0, 100);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-18 15:40:50 +08:00
|
|
|
|
private partial class Button : DialogButton
|
2017-12-18 15:29:40 +08:00
|
|
|
|
{
|
2019-09-05 15:31:10 +08:00
|
|
|
|
// required to ensure keyboard navigation always starts from an extremity (unless the cursor is moved)
|
|
|
|
|
protected override bool OnHover(HoverEvent e) => true;
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnMouseMove(MouseMoveEvent e)
|
2017-12-28 08:56:10 +08:00
|
|
|
|
{
|
2021-07-06 18:07:25 +08:00
|
|
|
|
State = SelectionState.Selected;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnMouseMove(e);
|
2017-12-28 08:56:10 +08:00
|
|
|
|
}
|
2017-05-17 20:57:01 +08:00
|
|
|
|
}
|
2019-09-06 16:17:30 +08:00
|
|
|
|
|
|
|
|
|
protected override bool Handle(UIEvent e)
|
|
|
|
|
{
|
|
|
|
|
switch (e)
|
|
|
|
|
{
|
2022-06-24 20:25:23 +08:00
|
|
|
|
case ScrollEvent:
|
2019-09-06 16:17:30 +08:00
|
|
|
|
if (ReceivePositionalInputAt(e.ScreenSpaceMousePosition))
|
|
|
|
|
return globalAction.TriggerEvent(e);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.Handle(e);
|
|
|
|
|
}
|
2017-03-28 17:09:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|