2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using System.Collections.Generic;
|
2018-06-09 07:28:02 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Input.Bindings;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-06-09 07:28:02 +00:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2019-02-28 05:55:45 +00:00
|
|
|
|
using Humanizer;
|
2019-04-02 05:51:28 +00:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
2018-06-09 07:28:02 +00:00
|
|
|
|
public abstract class GameplayMenuOverlay : OverlayContainer, IKeyBindingHandler<GlobalAction>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-07-17 10:08:50 +00:00
|
|
|
|
protected const int TRANSITION_DURATION = 200;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private const int button_height = 70;
|
|
|
|
|
private const float background_alpha = 0.75f;
|
|
|
|
|
|
2018-09-26 05:01:15 +00:00
|
|
|
|
protected override bool BlockNonPositionalInput => true;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-26 05:01:15 +00:00
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
public Action OnRetry;
|
|
|
|
|
public Action OnQuit;
|
|
|
|
|
|
2018-06-09 07:28:02 +00:00
|
|
|
|
/// <summary>
|
2018-06-27 03:57:26 +00:00
|
|
|
|
/// Action that is invoked when <see cref="GlobalAction.Back"/> is triggered.
|
2018-06-09 07:28:02 +00:00
|
|
|
|
/// </summary>
|
2019-03-24 03:03:06 +00:00
|
|
|
|
protected virtual Action BackAction => () => InternalButtons.Children.LastOrDefault()?.Click();
|
2018-06-09 07:28:02 +00:00
|
|
|
|
|
2019-01-27 18:19:20 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Action that is invoked when <see cref="GlobalAction.Select"/> is triggered.
|
|
|
|
|
/// </summary>
|
2019-03-24 03:03:06 +00:00
|
|
|
|
protected virtual Action SelectAction => () => InternalButtons.Children.FirstOrDefault(f => f.Selected.Value)?.Click();
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public abstract string Header { get; }
|
2019-03-24 03:03:06 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public abstract string Description { get; }
|
|
|
|
|
|
2020-08-15 11:36:00 +00:00
|
|
|
|
protected ButtonContainer InternalButtons;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public IReadOnlyList<DialogButton> Buttons => InternalButtons;
|
|
|
|
|
|
|
|
|
|
private FillFlowContainer retryCounterContainer;
|
|
|
|
|
|
|
|
|
|
protected GameplayMenuOverlay()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
2020-08-15 11:36:00 +00:00
|
|
|
|
State.ValueChanged += s => InternalButtons.Deselect();
|
2018-04-13 09:19:50 +00: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[]
|
|
|
|
|
{
|
|
|
|
|
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 = Header,
|
2019-02-20 07:52:36 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 30),
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Spacing = new Vector2(5, 0),
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Colour = colours.Yellow,
|
|
|
|
|
Shadow = true,
|
|
|
|
|
ShadowColour = new Color4(0, 0, 0, 0.25f)
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = Description,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Shadow = true,
|
|
|
|
|
ShadowColour = new Color4(0, 0, 0, 0.25f)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-08-15 11:36:00 +00:00
|
|
|
|
InternalButtons = new ButtonContainer
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Masking = true,
|
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.6f),
|
|
|
|
|
Radius = 50
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
retryCounterContainer = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
updateRetryCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int retries;
|
|
|
|
|
|
|
|
|
|
public int Retries
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == retries)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
retries = value;
|
|
|
|
|
if (retryCounterContainer != null)
|
|
|
|
|
updateRetryCount();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-17 10:08:50 +00:00
|
|
|
|
protected override void PopIn() => this.FadeIn(TRANSITION_DURATION, Easing.In);
|
|
|
|
|
protected override void PopOut() => this.FadeOut(TRANSITION_DURATION, Easing.In);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
// Don't let mouse down events through the overlay or people can click circles while paused.
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e) => true;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnMouseMove(MouseMoveEvent e) => true;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
protected void AddButton(string text, Color4 colour, Action action)
|
|
|
|
|
{
|
|
|
|
|
var button = new Button
|
|
|
|
|
{
|
|
|
|
|
Text = text,
|
|
|
|
|
ButtonColour = colour,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Height = button_height,
|
|
|
|
|
Action = delegate
|
|
|
|
|
{
|
|
|
|
|
action?.Invoke();
|
|
|
|
|
Hide();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-02-22 08:51:39 +00:00
|
|
|
|
button.Selected.ValueChanged += selected => buttonSelectionChanged(button, selected.NewValue);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
InternalButtons.Add(button);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-09 07:28:02 +00:00
|
|
|
|
public bool OnPressed(GlobalAction action)
|
|
|
|
|
{
|
2019-03-24 03:03:06 +00:00
|
|
|
|
switch (action)
|
2019-01-27 18:19:20 +00:00
|
|
|
|
{
|
2020-03-02 09:55:28 +00:00
|
|
|
|
case GlobalAction.SelectPrevious:
|
2020-08-15 11:36:00 +00:00
|
|
|
|
InternalButtons.SelectPrevious();
|
2020-03-02 09:55:28 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case GlobalAction.SelectNext:
|
2020-08-15 11:36:00 +00:00
|
|
|
|
InternalButtons.SelectNext();
|
2020-03-02 09:55:28 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
2019-03-24 03:03:06 +00:00
|
|
|
|
case GlobalAction.Back:
|
|
|
|
|
BackAction.Invoke();
|
|
|
|
|
return true;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2019-03-24 03:03:06 +00:00
|
|
|
|
case GlobalAction.Select:
|
|
|
|
|
SelectAction.Invoke();
|
|
|
|
|
return true;
|
2019-01-27 18:19:20 +00:00
|
|
|
|
}
|
2019-03-24 03:19:09 +00:00
|
|
|
|
|
|
|
|
|
return false;
|
2018-06-09 07:28:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-22 04:22:34 +00:00
|
|
|
|
public void OnReleased(GlobalAction action)
|
2019-03-24 03:19:09 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2018-06-09 07:28:02 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private void buttonSelectionChanged(DialogButton button, bool isSelected)
|
|
|
|
|
{
|
|
|
|
|
if (!isSelected)
|
2020-08-15 11:36:00 +00:00
|
|
|
|
InternalButtons.Deselect();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
else
|
2020-08-15 11:36:00 +00:00
|
|
|
|
InternalButtons.Select(button);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateRetryCount()
|
|
|
|
|
{
|
|
|
|
|
// "You've retried 1,065 times in this session"
|
|
|
|
|
// "You've retried 1 time in this session"
|
|
|
|
|
|
|
|
|
|
retryCounterContainer.Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = "You've retried ",
|
|
|
|
|
Shadow = true,
|
|
|
|
|
ShadowColour = new Color4(0, 0, 0, 0.25f),
|
2019-02-12 04:04:46 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 18),
|
2018-04-13 09:19:50 +00:00
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2019-02-28 05:55:45 +00:00
|
|
|
|
Text = "time".ToQuantity(retries),
|
2019-02-12 04:04:46 +00:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 18),
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Shadow = true,
|
|
|
|
|
ShadowColour = new Color4(0, 0, 0, 0.25f),
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2019-02-28 05:55:45 +00:00
|
|
|
|
Text = " in this session",
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Shadow = true,
|
|
|
|
|
ShadowColour = new Color4(0, 0, 0, 0.25f),
|
2019-02-12 04:04:46 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 18),
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-15 11:36:00 +00:00
|
|
|
|
protected class ButtonContainer : FillFlowContainer<DialogButton>
|
|
|
|
|
{
|
|
|
|
|
private int selectedIndex = -1;
|
|
|
|
|
|
|
|
|
|
private void setSelected(int value)
|
|
|
|
|
{
|
|
|
|
|
if (selectedIndex == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Deselect the previously-selected button
|
|
|
|
|
if (selectedIndex != -1)
|
|
|
|
|
this[selectedIndex].Selected.Value = false;
|
|
|
|
|
|
|
|
|
|
selectedIndex = value;
|
|
|
|
|
|
|
|
|
|
// Select the newly-selected button
|
|
|
|
|
if (selectedIndex != -1)
|
|
|
|
|
this[selectedIndex].Selected.Value = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SelectNext()
|
|
|
|
|
{
|
|
|
|
|
if (selectedIndex == -1 || selectedIndex == Count - 1)
|
|
|
|
|
setSelected(0);
|
|
|
|
|
else
|
|
|
|
|
setSelected(selectedIndex + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SelectPrevious()
|
|
|
|
|
{
|
|
|
|
|
if (selectedIndex == -1 || selectedIndex == 0)
|
|
|
|
|
setSelected(Count - 1);
|
|
|
|
|
else
|
|
|
|
|
setSelected(selectedIndex - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Deselect() => setSelected(-1);
|
|
|
|
|
public void Select(DialogButton button) => setSelected(IndexOf(button));
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private class Button : DialogButton
|
|
|
|
|
{
|
2019-09-05 07:31:10 +00: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 03:02:47 +00:00
|
|
|
|
protected override bool OnMouseMove(MouseMoveEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
Selected.Value = true;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnMouseMove(e);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-06 08:17:30 +00:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private GlobalActionContainer globalAction { get; set; }
|
|
|
|
|
|
|
|
|
|
protected override bool Handle(UIEvent e)
|
|
|
|
|
{
|
|
|
|
|
switch (e)
|
|
|
|
|
{
|
|
|
|
|
case ScrollEvent _:
|
|
|
|
|
if (ReceivePositionalInputAt(e.ScreenSpaceMousePosition))
|
|
|
|
|
return globalAction.TriggerEvent(e);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.Handle(e);
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|