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
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2017-03-02 20:40:55 +08:00
|
|
|
|
using System;
|
2017-03-05 02:42:37 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-03-02 20:40:55 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
using osuTK.Input;
|
2017-05-20 10:44:36 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2020-09-15 02:19:18 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
|
using System.Linq;
|
2022-01-28 12:53:48 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-03 09:20:30 +08:00
|
|
|
|
namespace osu.Game.Screens.Select.Options
|
2017-03-02 20:40:55 +08:00
|
|
|
|
{
|
2017-06-29 01:18:12 +08:00
|
|
|
|
public class BeatmapOptionsOverlay : OsuFocusedOverlayContainer
|
2017-03-02 20:40:55 +08:00
|
|
|
|
{
|
|
|
|
|
private const float transition_duration = 500;
|
2017-03-19 01:31:14 +08:00
|
|
|
|
private const float x_position = 0.2f;
|
|
|
|
|
private const float x_movement = 0.8f;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-03 15:54:59 +08:00
|
|
|
|
private const float height = 100;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly Box holder;
|
|
|
|
|
private readonly FillFlowContainer<BeatmapOptionsButton> buttonsContainer;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-30 19:45:41 +08:00
|
|
|
|
public override bool BlockScreenWideMouse => false;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-02 20:40:55 +08:00
|
|
|
|
public BeatmapOptionsOverlay()
|
|
|
|
|
{
|
2017-03-03 15:11:23 +08:00
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
Anchor = Anchor.BottomLeft;
|
|
|
|
|
Origin = Anchor.BottomLeft;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-02 20:40:55 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-03-03 15:11:23 +08:00
|
|
|
|
holder = new Box
|
2017-03-02 20:40:55 +08:00
|
|
|
|
{
|
2017-03-03 15:11:23 +08:00
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2017-03-02 20:40:55 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-03-03 15:11:23 +08:00
|
|
|
|
Height = 0.5f,
|
|
|
|
|
Scale = new Vector2(1, 0),
|
|
|
|
|
Colour = Color4.Black.Opacity(0.5f),
|
2017-03-02 20:40:55 +08:00
|
|
|
|
},
|
2017-07-12 02:21:58 +08:00
|
|
|
|
buttonsContainer = new ReverseChildIDFillFlowContainer<BeatmapOptionsButton>
|
2017-03-02 20:40:55 +08:00
|
|
|
|
{
|
2017-03-03 15:54:59 +08:00
|
|
|
|
Height = height,
|
2017-03-19 01:31:14 +08:00
|
|
|
|
RelativePositionAxes = Axes.X,
|
2017-03-03 12:53:17 +08:00
|
|
|
|
AutoSizeAxes = Axes.X,
|
2017-03-02 20:40:55 +08:00
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-14 21:20:38 +08:00
|
|
|
|
/// <param name="firstLine">Text in the first line.</param>
|
|
|
|
|
/// <param name="secondLine">Text in the second line.</param>
|
|
|
|
|
/// <param name="colour">Colour of the button.</param>
|
|
|
|
|
/// <param name="icon">Icon of the button.</param>
|
2017-08-11 15:11:46 +08:00
|
|
|
|
/// <param name="action">Binding the button does.</param>
|
2022-01-28 12:53:48 +08:00
|
|
|
|
public void AddButton(LocalisableString firstLine, string secondLine, IconUsage icon, Color4 colour, Action action)
|
2017-03-14 19:38:21 +08:00
|
|
|
|
{
|
2018-03-06 16:20:58 +08:00
|
|
|
|
var button = new BeatmapOptionsButton
|
2017-03-14 19:38:21 +08:00
|
|
|
|
{
|
|
|
|
|
FirstLineText = firstLine,
|
2017-03-14 21:20:38 +08:00
|
|
|
|
SecondLineText = secondLine,
|
2017-03-14 19:38:21 +08:00
|
|
|
|
Icon = icon,
|
|
|
|
|
ButtonColour = colour,
|
|
|
|
|
Action = () =>
|
|
|
|
|
{
|
|
|
|
|
Hide();
|
|
|
|
|
action?.Invoke();
|
|
|
|
|
},
|
2018-03-06 16:20:58 +08:00
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-10-05 08:14:19 +08:00
|
|
|
|
buttonsContainer.Add(button);
|
2017-03-14 19:38:21 +08:00
|
|
|
|
}
|
2020-09-15 02:18:00 +08:00
|
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
base.PopIn();
|
|
|
|
|
|
|
|
|
|
this.FadeIn(transition_duration, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
if (buttonsContainer.Position.X == 1 || Alpha == 0)
|
|
|
|
|
buttonsContainer.MoveToX(x_position - x_movement);
|
|
|
|
|
|
|
|
|
|
holder.ScaleTo(new Vector2(1, 1), transition_duration / 2, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
buttonsContainer.MoveToX(x_position, transition_duration, Easing.OutQuint);
|
|
|
|
|
buttonsContainer.TransformSpacingTo(Vector2.Zero, transition_duration, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
base.PopOut();
|
|
|
|
|
|
|
|
|
|
holder.ScaleTo(new Vector2(1, 0), transition_duration / 2, Easing.InSine);
|
|
|
|
|
|
|
|
|
|
buttonsContainer.MoveToX(x_position + x_movement, transition_duration, Easing.InSine);
|
|
|
|
|
buttonsContainer.TransformSpacingTo(new Vector2(200f, 0f), transition_duration, Easing.InSine);
|
|
|
|
|
|
|
|
|
|
this.FadeOut(transition_duration, Easing.InQuint);
|
|
|
|
|
}
|
2020-09-15 02:19:18 +08:00
|
|
|
|
|
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
|
|
|
|
{
|
2020-09-15 02:22:16 +08:00
|
|
|
|
// don't absorb control as ToolbarRulesetSelector uses control + number to navigate
|
|
|
|
|
if (e.ControlPressed) return false;
|
|
|
|
|
|
2020-09-15 02:19:18 +08:00
|
|
|
|
if (!e.Repeat && e.Key >= Key.Number1 && e.Key <= Key.Number9)
|
|
|
|
|
{
|
|
|
|
|
int requested = e.Key - Key.Number1;
|
|
|
|
|
|
|
|
|
|
// go reverse as buttonsContainer is a ReverseChildIDFillFlowContainer
|
|
|
|
|
BeatmapOptionsButton found = buttonsContainer.Children.ElementAtOrDefault((buttonsContainer.Children.Count - 1) - requested);
|
|
|
|
|
|
|
|
|
|
if (found != null)
|
|
|
|
|
{
|
2021-08-04 16:27:44 +08:00
|
|
|
|
found.TriggerClick();
|
2020-09-15 02:19:18 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.OnKeyDown(e);
|
|
|
|
|
}
|
2017-03-02 20:40:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|