1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 00:42:55 +08:00

let mods button have selected mod icons

This commit is contained in:
LeNitrous 2019-04-10 21:53:13 +08:00
parent a5ff7d58db
commit 22f9339b01
4 changed files with 74 additions and 27 deletions

View File

@ -20,9 +20,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,6 +30,7 @@ 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>
/// <param name="hotkey">Hotkey of the button.</param>
@ -41,21 +39,16 @@ namespace osu.Game.Screens.Select
/// <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)
public void AddButton(FooterButton button, 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,
};
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);
@ -71,10 +64,10 @@ namespace osu.Game.Screens.Select
/// <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, string text, Color4 colour, OverlayContainer overlay, Key? hotkey = null, float depth = 0)
{
overlays.Add(overlay);
AddButton(text, colour, () =>
AddButton(button, text, colour, () =>
{
foreach (var o in overlays)
{

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;
@ -61,8 +62,18 @@ namespace osu.Game.Screens.Select
public FooterButton()
{
AutoSizeAxes = Axes.Both;
Children = new Drawable[]
{
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 +89,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,48 @@
// 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.Rulesets.Mods;
using osu.Game.Rulesets.UI;
using System;
using System.Collections.Generic;
using osuTK;
namespace osu.Game.Screens.Select
{
public class FooterButtonMods : FooterButton
{
private readonly Bindable<IEnumerable<Mod>> selectedMods = new Bindable<IEnumerable<Mod>>();
private readonly FillFlowContainer<ModIcon> modIcons;
public FooterButtonMods(Bindable<IEnumerable<Mod>> mods) : base()
{
Add(modIcons = new FillFlowContainer<ModIcon>
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding {Left = 80, Right = 20}
});
if (mods != null)
{
selectedMods.BindTo(mods);
selectedMods.ValueChanged += updateModIcons;
}
}
private void updateModIcons(ValueChangedEvent<IEnumerable<Mod>> mods)
{
modIcons.Clear();
foreach (Mod mod in mods.NewValue)
{
modIcons.Add(new ModIcon(mod) { Scale = new Vector2(0.4f) });
}
}
}
}

View File

@ -224,9 +224,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(selectedMods), @"mods", colours.Yellow, ModSelect, Key.F1);
Footer.AddButton(new FooterButton(), @"random", colours.Green, triggerRandom, Key.F2);
Footer.AddButton(new FooterButton(), @"options", colours.Blue, 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);