osu/osu.Game/Screens/Select/FooterButtonRandom.cs

84 lines
2.5 KiB
C#
Raw Normal View History

2019-04-10 21:47:32 +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.
using System;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
2021-09-16 09:26:12 +00:00
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Input.Bindings;
using osuTK;
2019-04-10 21:47:32 +00:00
namespace osu.Game.Screens.Select
{
public class FooterButtonRandom : FooterButton
{
public Action NextRandom { get; set; }
public Action PreviousRandom { get; set; }
2020-06-04 08:58:19 +00:00
private bool rewindSearch;
2019-04-10 21:47:32 +00:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
SelectedColour = colours.Green;
DeselectedColour = SelectedColour.Opacity(0.5f);
Text = @"random";
Action = () =>
{
if (rewindSearch)
{
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);
PreviousRandom.Invoke();
}
else
{
NextRandom.Invoke();
}
};
2019-04-10 21:47:32 +00:00
}
2021-09-16 09:26:12 +00:00
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
2021-09-16 09:26:12 +00:00
rewindSearch = e.Action == GlobalAction.SelectPreviousRandom;
2020-06-07 04:06:18 +00:00
2021-09-16 09:26:12 +00:00
if (e.Action != GlobalAction.SelectNextRandom && e.Action != GlobalAction.SelectPreviousRandom)
{
return false;
}
2020-06-07 04:06:18 +00:00
2021-08-04 08:27:44 +00:00
TriggerClick();
return true;
}
2021-09-16 09:26:12 +00:00
public override void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
2021-09-16 09:26:12 +00:00
if (e.Action == GlobalAction.SelectPreviousRandom)
{
2020-06-04 08:58:19 +00:00
rewindSearch = false;
}
}
2019-04-10 21:47:32 +00:00
}
}