1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 10:13:22 +08:00
osu-lazer/osu.Game/Screens/Select/FooterButtonRandom.cs

92 lines
2.7 KiB
C#
Raw Normal View History

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.
using System;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
2019-04-11 05:47:32 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
2019-04-11 05:47:32 +08:00
using osu.Game.Graphics.Sprites;
using osu.Game.Input.Bindings;
2019-04-11 05:47:32 +08:00
namespace osu.Game.Screens.Select
{
public class FooterButtonRandom : FooterButton
{
public Action PrimaryAction { get; set; }
public Action SecondaryAction { get; set; }
2019-04-11 05:47:32 +08:00
private readonly SpriteText secondaryText;
private bool secondaryActive;
public FooterButtonRandom()
{
2019-05-03 16:38:15 +08:00
TextContainer.Add(secondaryText = new OsuSpriteText
2019-04-11 05:47:32 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = @"rewind",
Alpha = 0,
2019-04-11 05:47:32 +08:00
});
// force both text sprites to always be present to avoid width flickering while they're being swapped out
SpriteText.AlwaysPresent = secondaryText.AlwaysPresent = true;
2019-04-11 05:47:32 +08:00
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
SelectedColour = colours.Green;
DeselectedColour = SelectedColour.Opacity(0.5f);
Text = @"random";
Hotkey = GlobalAction.SelectNextRandom;
2019-04-11 05:47:32 +08:00
}
private void updateText()
{
if (secondaryActive)
{
2019-05-03 16:38:15 +08:00
SpriteText.FadeOut(120, Easing.InQuad);
2019-04-11 05:47:32 +08:00
secondaryText.FadeIn(120, Easing.InQuad);
}
else
{
2019-05-03 16:38:15 +08:00
SpriteText.FadeIn(120, Easing.InQuad);
2019-04-11 05:47:32 +08:00
secondaryText.FadeOut(120, Easing.InQuad);
}
}
public override bool OnPressed(GlobalAction action)
{
switch (action)
{
case GlobalAction.SelectPreviousRandom:
secondaryActive = true;
Action = SecondaryAction;
updateText();
Click();
return true;
2020-06-04 12:59:04 +08:00
case GlobalAction.SelectNextRandom:
Action = PrimaryAction;
updateText();
Click();
return true;
2020-06-04 12:59:04 +08:00
default:
return false;
}
}
public override void OnReleased(GlobalAction action)
{
if (action == GlobalAction.SelectPreviousRandom)
{
secondaryActive = false;
updateText();
}
}
2019-04-11 05:47:32 +08:00
}
}