2019-04-11 05:47:32 +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.
|
|
|
|
|
|
2020-06-04 12:07:50 +08:00
|
|
|
|
using System;
|
2019-05-08 18:03:26 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2021-04-07 17:29:45 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2021-09-16 17:26:12 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2019-05-08 18:03:26 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2021-04-07 17:29:45 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2020-06-04 12:07:50 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2021-04-07 17:29:45 +08:00
|
|
|
|
using osuTK;
|
2022-04-29 15:12:20 +08:00
|
|
|
|
using osuTK.Input;
|
2019-04-11 05:47:32 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select
|
|
|
|
|
{
|
|
|
|
|
public class FooterButtonRandom : FooterButton
|
|
|
|
|
{
|
2020-06-04 17:00:29 +08:00
|
|
|
|
public Action NextRandom { get; set; }
|
|
|
|
|
public Action PreviousRandom { get; set; }
|
2020-06-04 12:07:50 +08:00
|
|
|
|
|
2020-06-04 16:58:19 +08:00
|
|
|
|
private bool rewindSearch;
|
2019-04-11 05:47:32 +08:00
|
|
|
|
|
2019-05-08 18:03:26 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
SelectedColour = colours.Green;
|
|
|
|
|
DeselectedColour = SelectedColour.Opacity(0.5f);
|
2022-04-29 15:10:19 +08:00
|
|
|
|
updateText();
|
2021-04-07 17:29:45 +08:00
|
|
|
|
|
2020-06-07 11:34:19 +08:00
|
|
|
|
Action = () =>
|
|
|
|
|
{
|
|
|
|
|
if (rewindSearch)
|
|
|
|
|
{
|
2021-04-07 17:29:45 +08:00
|
|
|
|
const double fade_time = 500;
|
|
|
|
|
|
|
|
|
|
OsuSpriteText rewindSpriteText;
|
|
|
|
|
|
|
|
|
|
TextContainer.Add(rewindSpriteText = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Text = @"rewind",
|
|
|
|
|
AlwaysPresent = true, // make sure the button is sized large enough to always show this
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rewindSpriteText.FadeOutFromOne(fade_time, Easing.In);
|
|
|
|
|
rewindSpriteText.MoveTo(Vector2.Zero).MoveTo(new Vector2(0, 10), fade_time, Easing.In);
|
|
|
|
|
rewindSpriteText.Expire();
|
|
|
|
|
|
|
|
|
|
SpriteText.FadeInFromZero(fade_time, Easing.In);
|
|
|
|
|
|
2020-06-07 11:34:19 +08:00
|
|
|
|
PreviousRandom.Invoke();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NextRandom.Invoke();
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-04-11 05:47:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-29 15:10:19 +08:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
|
|
|
|
{
|
|
|
|
|
updateText(e.ShiftPressed);
|
|
|
|
|
return base.OnKeyDown(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnKeyUp(KeyUpEvent e)
|
|
|
|
|
{
|
|
|
|
|
updateText(e.ShiftPressed);
|
|
|
|
|
base.OnKeyUp(e);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-29 01:04:52 +08:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
|
{
|
2022-04-29 15:12:20 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// this uses OR to handle rewinding when clicks are triggered by other sources (i.e. right button in OnMouseUp).
|
|
|
|
|
rewindSearch |= e.ShiftPressed;
|
|
|
|
|
return base.OnClick(e);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
rewindSearch = false;
|
|
|
|
|
}
|
2022-04-29 01:04:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
|
|
|
|
{
|
2022-04-29 15:12:20 +08:00
|
|
|
|
if (e.Button == MouseButton.Right)
|
|
|
|
|
{
|
|
|
|
|
rewindSearch = true;
|
|
|
|
|
TriggerClick();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-29 01:04:52 +08:00
|
|
|
|
base.OnMouseUp(e);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2020-06-04 12:07:50 +08:00
|
|
|
|
{
|
2021-09-16 17:26:12 +08:00
|
|
|
|
rewindSearch = e.Action == GlobalAction.SelectPreviousRandom;
|
2020-06-07 12:06:18 +08:00
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
if (e.Action != GlobalAction.SelectNextRandom && e.Action != GlobalAction.SelectPreviousRandom)
|
2020-06-04 12:07:50 +08:00
|
|
|
|
{
|
2020-06-07 11:34:19 +08:00
|
|
|
|
return false;
|
2020-06-04 12:07:50 +08:00
|
|
|
|
}
|
2020-06-07 12:06:18 +08:00
|
|
|
|
|
2021-08-04 16:27:44 +08:00
|
|
|
|
TriggerClick();
|
2020-06-07 11:34:19 +08:00
|
|
|
|
return true;
|
2020-06-04 12:07:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
public override void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
2020-06-04 12:07:50 +08:00
|
|
|
|
{
|
2021-09-16 17:26:12 +08:00
|
|
|
|
if (e.Action == GlobalAction.SelectPreviousRandom)
|
2020-06-04 12:07:50 +08:00
|
|
|
|
{
|
2020-06-04 16:58:19 +08:00
|
|
|
|
rewindSearch = false;
|
2020-06-04 12:07:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-29 15:10:19 +08:00
|
|
|
|
|
|
|
|
|
private void updateText(bool rewind = false) => Text = rewind ? "rewind" : "random";
|
2019-04-11 05:47:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|