mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:57:39 +08:00
Move button definitions to their respective classes
This commit is contained in:
parent
0693290ad4
commit
772eb460fb
@ -30,54 +30,39 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
private readonly FillFlowContainer<FooterButton> buttons;
|
||||
|
||||
/// <param name="button">Button to be added.</param>
|
||||
/// <param name="text">Text on the button.</param>
|
||||
/// <param name="colour">Colour of the button.</param>
|
||||
private readonly List<OverlayContainer> overlays = new List<OverlayContainer>();
|
||||
|
||||
/// <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="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(FooterButton button, string text, Color4 colour, Action action, Key? hotkey = null, float depth = 0)
|
||||
public void AddButton(FooterButton button, OverlayContainer overlay, Key? hotkey = null)
|
||||
{
|
||||
overlays.Add(overlay);
|
||||
AddButton(button, () => showOverlay(overlay), hotkey);
|
||||
}
|
||||
|
||||
/// <param name="button">Button to be added.</param>
|
||||
/// <param name="action">Action the button does.</param>
|
||||
/// <param name="hotkey">Hotkey of the button.</param>
|
||||
public void AddButton(FooterButton button, Action action, Key? hotkey = null)
|
||||
{
|
||||
button.Text = text;
|
||||
button.Depth = depth;
|
||||
button.SelectedColour = colour;
|
||||
button.DeselectedColour = colour.Opacity(0.5f);
|
||||
button.Hotkey = hotkey;
|
||||
button.Hovered = updateModeLight;
|
||||
button.HoverLost = updateModeLight;
|
||||
button.Action = action;
|
||||
|
||||
buttons.Add(button);
|
||||
buttons.SetLayoutPosition(button, -depth);
|
||||
}
|
||||
|
||||
private readonly List<OverlayContainer> overlays = new List<OverlayContainer>();
|
||||
|
||||
/// <param name="button">THe button to be added.</param>
|
||||
/// <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="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(FooterButton button, string text, Color4 colour, OverlayContainer overlay, Key? hotkey = null, float depth = 0)
|
||||
private void showOverlay(OverlayContainer overlay)
|
||||
{
|
||||
overlays.Add(overlay);
|
||||
AddButton(button, text, colour, () =>
|
||||
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);
|
||||
|
@ -7,6 +7,9 @@ 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;
|
||||
|
||||
namespace osu.Game.Screens.Select
|
||||
@ -34,6 +37,14 @@ namespace osu.Game.Screens.Select
|
||||
modDisplay.Current = mods;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
SelectedColour = colours.Yellow;
|
||||
DeselectedColour = SelectedColour.Opacity(0.5f);
|
||||
Text = @"mods";
|
||||
}
|
||||
|
||||
private class FooterModDisplay : ModDisplay
|
||||
{
|
||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Parent?.Parent?.ReceivePositionalInputAt(screenSpacePos) ?? false;
|
||||
|
@ -1,9 +1,12 @@
|
||||
// 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;
|
||||
|
||||
namespace osu.Game.Screens.Select
|
||||
@ -24,6 +27,14 @@ namespace osu.Game.Screens.Select
|
||||
});
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
SelectedColour = colours.Green;
|
||||
DeselectedColour = SelectedColour.Opacity(0.5f);
|
||||
Text = @"random";
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(KeyDownEvent e)
|
||||
{
|
||||
secondaryActive = e.ShiftPressed;
|
||||
|
@ -223,9 +223,9 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
if (Footer != null)
|
||||
{
|
||||
Footer.AddButton(new FooterButtonMods(mods), @"mods", colours.Yellow, ModSelect, Key.F1);
|
||||
Footer.AddButton(new FooterButtonRandom(), @"random", colours.Green, triggerRandom, Key.F2);
|
||||
Footer.AddButton(new FooterButton(), @"options", colours.Blue, BeatmapOptions, Key.F3);
|
||||
Footer.AddButton(new FooterButtonMods(mods), ModSelect, Key.F1);
|
||||
Footer.AddButton(new FooterButtonRandom(), triggerRandom, Key.F2);
|
||||
Footer.AddButton(new FooterButtonOptions(), BeatmapOptions, Key.F3);
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user