Merge pull request #4616 from LeNitrous/refactor-select-footer

Refactor song select footer buttons
This commit is contained in:
Dan Balasescu 2019-05-08 19:57:51 +09:00 committed by GitHub
commit 255df3d329
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 203 additions and 64 deletions

View File

@ -24,6 +24,8 @@ namespace osu.Game.Screens.Play.HUD
public bool DisplayUnrankedText = true;
public bool AllowExpand = true;
private readonly Bindable<IReadOnlyList<Mod>> current = new Bindable<IReadOnlyList<Mod>>();
public Bindable<IReadOnlyList<Mod>> Current
@ -88,7 +90,9 @@ namespace osu.Game.Screens.Play.HUD
protected override void LoadComplete()
{
base.LoadComplete();
appearTransform();
iconsContainer.FadeInFromZero(fade_duration, Easing.OutQuint);
}
private void appearTransform()
@ -98,14 +102,17 @@ namespace osu.Game.Screens.Play.HUD
else
unrankedText.Hide();
iconsContainer.FinishTransforms();
iconsContainer.FadeInFromZero(fade_duration, Easing.OutQuint);
expand();
using (iconsContainer.BeginDelayedSequence(1200))
contract();
}
private void expand() => iconsContainer.TransformSpacingTo(new Vector2(5, 0), 500, Easing.OutQuint);
private void expand()
{
if (AllowExpand)
iconsContainer.TransformSpacingTo(new Vector2(5, 0), 500, Easing.OutQuint);
}
private void contract() => iconsContainer.TransformSpacingTo(new Vector2(-25, 0), 500, Easing.OutQuint);

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Linq;
using osuTK;
using osuTK.Graphics;
using osuTK.Input;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -20,9 +19,6 @@ namespace osu.Game.Screens.Select
{
private readonly Box modeLight;
private const float play_song_select_button_width = 100;
private const float play_song_select_button_height = 50;
public const float HEIGHT = 50;
public const int TRANSITION_LENGTH = 300;
@ -33,57 +29,36 @@ namespace osu.Game.Screens.Select
private readonly FillFlowContainer<FooterButton> buttons;
/// <param name="text">Text on the button.</param>
/// <param name="colour">Colour of the button.</param>
/// <param name="hotkey">Hotkey of the button.</param>
/// <param name="action">Action the button does.</param>
/// <param name="depth">
/// <para>Higher depth to be put on the left, and lower to be put on the right.</para>
/// <para>Notice this is different to <see cref="Options.BeatmapOptionsOverlay"/>!</para>
/// </param>
public void AddButton(string text, Color4 colour, Action action, Key? hotkey = null, float depth = 0)
{
var button = new FooterButton
{
Text = text,
Height = play_song_select_button_height,
Width = play_song_select_button_width,
Depth = depth,
SelectedColour = colour,
DeselectedColour = colour.Opacity(0.5f),
Hotkey = hotkey,
Hovered = updateModeLight,
HoverLost = updateModeLight,
Action = action,
};
buttons.Add(button);
buttons.SetLayoutPosition(button, -depth);
}
private readonly List<OverlayContainer> overlays = new List<OverlayContainer>();
/// <param name="text">Text on the button.</param>
/// <param name="colour">Colour of the button.</param>
/// <param name="hotkey">Hotkey of the button.</param>
/// <param name="button">THe button to be added.</param>
/// <param name="overlay">The <see cref="OverlayContainer"/> to be toggled by this button.</param>
/// <param name="depth">
/// <para>Higher depth to be put on the left, and lower to be put on the right.</para>
/// <para>Notice this is different to <see cref="Options.BeatmapOptionsOverlay"/>!</para>
/// </param>
public void AddButton(string text, Color4 colour, OverlayContainer overlay, Key? hotkey = null, float depth = 0)
public void AddButton(FooterButton button, OverlayContainer overlay)
{
overlays.Add(overlay);
AddButton(text, colour, () =>
button.Action = () => showOverlay(overlay);
AddButton(button);
}
/// <param name="button">Button to be added.</param>
public void AddButton(FooterButton button)
{
button.Hovered = updateModeLight;
button.HoverLost = updateModeLight;
buttons.Add(button);
}
private void showOverlay(OverlayContainer overlay)
{
foreach (var o in overlays)
{
foreach (var o in overlays)
{
if (o == overlay)
o.ToggleVisibility();
else
o.Hide();
}
}, hotkey, depth);
if (o == overlay)
o.ToggleVisibility();
else
o.Hide();
}
}
private void updateModeLight() => modeLight.FadeColour(buttons.FirstOrDefault(b => b.IsHovered)?.SelectedColour ?? Color4.Transparent, TRANSITION_LENGTH, Easing.OutQuint);

View File

@ -6,6 +6,7 @@ using osuTK;
using osuTK.Graphics;
using osuTK.Input;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
@ -20,11 +21,11 @@ namespace osu.Game.Screens.Select
public string Text
{
get => spriteText?.Text;
get => SpriteText?.Text;
set
{
if (spriteText != null)
spriteText.Text = value;
if (SpriteText != null)
SpriteText.Text = value;
}
}
@ -53,7 +54,8 @@ namespace osu.Game.Screens.Select
}
}
private readonly SpriteText spriteText;
protected readonly Container TextContainer;
protected readonly SpriteText SpriteText;
private readonly Box box;
private readonly Box light;
@ -61,8 +63,18 @@ namespace osu.Game.Screens.Select
public FooterButton()
{
AutoSizeAxes = Axes.Both;
Children = new Drawable[]
{
TextContainer = new Container
{
Size = new Vector2(100, 50),
Child = SpriteText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
},
box = new Box
{
RelativeSizeAxes = Axes.Both,
@ -78,11 +90,6 @@ namespace osu.Game.Screens.Select
EdgeSmoothness = new Vector2(2, 0),
RelativeSizeAxes = Axes.X,
},
spriteText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
};
}

View File

@ -0,0 +1,60 @@
// 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 osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Screens.Play.HUD;
using osu.Game.Rulesets.Mods;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Game.Graphics;
using osuTK;
using osuTK.Input;
namespace osu.Game.Screens.Select
{
public class FooterButtonMods : FooterButton
{
public FooterButtonMods(Bindable<IReadOnlyList<Mod>> mods)
{
FooterModDisplay modDisplay;
Add(new Container
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Child = modDisplay = new FooterModDisplay
{
DisplayUnrankedText = false,
Scale = new Vector2(0.8f)
},
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding { Left = 70 }
});
if (mods != null)
modDisplay.Current = mods;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
SelectedColour = colours.Yellow;
DeselectedColour = SelectedColour.Opacity(0.5f);
Text = @"mods";
Hotkey = Key.F1;
}
private class FooterModDisplay : ModDisplay
{
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Parent?.Parent?.ReceivePositionalInputAt(screenSpacePos) ?? false;
public FooterModDisplay()
{
AllowExpand = false;
}
}
}
}

View File

@ -0,0 +1,22 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Game.Graphics;
using osuTK.Input;
namespace osu.Game.Screens.Select
{
public class FooterButtonOptions : FooterButton
{
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
SelectedColour = colours.Blue;
DeselectedColour = SelectedColour.Opacity(0.5f);
Text = @"options";
Hotkey = Key.F3;
}
}
}

View File

@ -0,0 +1,68 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK.Input;
namespace osu.Game.Screens.Select
{
public class FooterButtonRandom : FooterButton
{
private readonly SpriteText secondaryText;
private bool secondaryActive;
public FooterButtonRandom()
{
TextContainer.Add(secondaryText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = @"rewind",
Alpha = 0
});
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
SelectedColour = colours.Green;
DeselectedColour = SelectedColour.Opacity(0.5f);
Text = @"random";
Hotkey = Key.F2;
}
protected override bool OnKeyDown(KeyDownEvent e)
{
secondaryActive = e.ShiftPressed;
updateText();
return base.OnKeyDown(e);
}
protected override bool OnKeyUp(KeyUpEvent e)
{
secondaryActive = e.ShiftPressed;
updateText();
return base.OnKeyUp(e);
}
private void updateText()
{
if (secondaryActive)
{
SpriteText.FadeOut(120, Easing.InQuad);
secondaryText.FadeIn(120, Easing.InQuad);
}
else
{
SpriteText.FadeIn(120, Easing.InQuad);
secondaryText.FadeOut(120, Easing.InQuad);
}
}
}
}

View File

@ -223,9 +223,9 @@ namespace osu.Game.Screens.Select
if (Footer != null)
{
Footer.AddButton(@"mods", colours.Yellow, ModSelect, Key.F1);
Footer.AddButton(@"random", colours.Green, triggerRandom, Key.F2);
Footer.AddButton(@"options", colours.Blue, BeatmapOptions, Key.F3);
Footer.AddButton(new FooterButtonMods(mods), ModSelect);
Footer.AddButton(new FooterButtonRandom { Action = triggerRandom });
Footer.AddButton(new FooterButtonOptions(), BeatmapOptions);
BeatmapOptions.AddButton(@"Delete", @"all difficulties", FontAwesome.Solid.Trash, colours.Pink, () => delete(Beatmap.Value.BeatmapSetInfo), Key.Number4, float.MaxValue);
BeatmapOptions.AddButton(@"Remove", @"from unplayed", FontAwesome.Regular.TimesCircle, colours.Purple, null, Key.Number1);