mirror of
https://github.com/ppy/osu.git
synced 2026-05-18 08:30:00 +08:00
0aff50fbf5
This aims to bring some conformity to naming to make it easier to understand component structure for new components. Renames are pulled out of the song select v2 changes and are more relevant there due to many new classes being added. - `V2` suffix is dropped, with v2 components being moved to a relevant V2 namespace. - Related classes have a prefix of the area they are used. - Experimenting with using partial/nested classes in the song select v2 implementation. Not committing to this yet but want to see how it plays out. - Moved base carousel components to a generic namespace to avoid confusion with actual beatmap carousel implementation.
199 lines
7.3 KiB
C#
199 lines
7.3 KiB
C#
// 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 System.Linq;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Bindables;
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Graphics.Sprites;
|
|
using osu.Framework.Input.Events;
|
|
using osu.Framework.Localisation;
|
|
using osu.Game.Beatmaps;
|
|
using osu.Game.Collections;
|
|
using osu.Game.Graphics;
|
|
using osu.Game.Graphics.Containers;
|
|
using osu.Game.Graphics.Sprites;
|
|
using osu.Game.Graphics.UserInterface;
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
|
using osu.Game.Localisation;
|
|
using osu.Game.Overlays;
|
|
using osuTK;
|
|
using osuTK.Graphics;
|
|
using osuTK.Input;
|
|
using WebCommonStrings = osu.Game.Resources.Localisation.Web.CommonStrings;
|
|
|
|
namespace osu.Game.Screens.SelectV2
|
|
{
|
|
public partial class FooterButtonOptions
|
|
{
|
|
public partial class Popover : OsuPopover
|
|
{
|
|
private FillFlowContainer buttonFlow = null!;
|
|
private readonly FooterButtonOptions footerButton;
|
|
|
|
[Cached]
|
|
private readonly OverlayColourProvider colourProvider;
|
|
|
|
private WorkingBeatmap beatmapWhenOpening = null!;
|
|
|
|
[Resolved]
|
|
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
|
|
|
|
public Popover(FooterButtonOptions footerButton, OverlayColourProvider colourProvider)
|
|
{
|
|
this.footerButton = footerButton;
|
|
this.colourProvider = colourProvider;
|
|
}
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load(ManageCollectionsDialog? manageCollectionsDialog, OsuColour colours, BeatmapManager? beatmapManager)
|
|
{
|
|
Content.Padding = new MarginPadding(5);
|
|
|
|
Child = buttonFlow = new FillFlowContainer
|
|
{
|
|
AutoSizeAxes = Axes.Both,
|
|
Direction = FillDirection.Vertical,
|
|
Spacing = new Vector2(3),
|
|
};
|
|
|
|
beatmapWhenOpening = beatmap.Value;
|
|
|
|
addHeader(CommonStrings.General);
|
|
addButton(SongSelectStrings.ManageCollections, FontAwesome.Solid.Book, () => manageCollectionsDialog?.Show());
|
|
|
|
addHeader(SongSelectStrings.ForAllDifficulties, beatmapWhenOpening.BeatmapSetInfo.ToString());
|
|
addButton(SongSelectStrings.DeleteBeatmap, FontAwesome.Solid.Trash, () => { }, colours.Red1); // songSelect?.DeleteBeatmap(beatmapWhenOpening.BeatmapSetInfo);
|
|
|
|
addHeader(SongSelectStrings.ForSelectedDifficulty, beatmapWhenOpening.BeatmapInfo.DifficultyName);
|
|
// TODO: make work, and make show "unplayed" or "played" based on status.
|
|
addButton(SongSelectStrings.MarkAsPlayed, FontAwesome.Regular.TimesCircle, null);
|
|
addButton(SongSelectStrings.ClearAllLocalScores, FontAwesome.Solid.Eraser, () => { }, colours.Red1); // songSelect?.ClearScores(beatmapWhenOpening.BeatmapInfo);
|
|
|
|
// if (songSelect != null && songSelect.AllowEditing)
|
|
addButton(SongSelectStrings.EditBeatmap, FontAwesome.Solid.PencilAlt, () => { }); // songSelect.Edit(beatmapWhenOpening.BeatmapInfo);
|
|
|
|
addButton(WebCommonStrings.ButtonsHide.ToSentence(), FontAwesome.Solid.Magic, () => beatmapManager?.Hide(beatmapWhenOpening.BeatmapInfo));
|
|
}
|
|
|
|
protected override void LoadComplete()
|
|
{
|
|
base.LoadComplete();
|
|
|
|
ScheduleAfterChildren(() => GetContainingFocusManager()!.ChangeFocus(this));
|
|
|
|
beatmap.BindValueChanged(_ => Hide());
|
|
}
|
|
|
|
private void addHeader(LocalisableString text, string? context = null)
|
|
{
|
|
var textFlow = new OsuTextFlowContainer
|
|
{
|
|
AutoSizeAxes = Axes.Y,
|
|
RelativeSizeAxes = Axes.X,
|
|
Padding = new MarginPadding(10),
|
|
};
|
|
|
|
textFlow.AddText(text, t => t.Font = OsuFont.Default.With(weight: FontWeight.SemiBold));
|
|
|
|
if (context != null)
|
|
{
|
|
textFlow.NewLine();
|
|
textFlow.AddText(context, t =>
|
|
{
|
|
t.Colour = colourProvider.Content2;
|
|
t.Font = t.Font.With(size: 13);
|
|
});
|
|
}
|
|
|
|
buttonFlow.Add(textFlow);
|
|
}
|
|
|
|
private void addButton(LocalisableString text, IconUsage icon, Action? action, Color4? colour = null)
|
|
{
|
|
var button = new OptionButton
|
|
{
|
|
Text = text,
|
|
Icon = icon,
|
|
TextColour = colour,
|
|
Action = () =>
|
|
{
|
|
Scheduler.AddDelayed(Hide, 50);
|
|
action?.Invoke();
|
|
},
|
|
};
|
|
|
|
buttonFlow.Add(button);
|
|
}
|
|
|
|
private partial class OptionButton : OsuButton
|
|
{
|
|
public IconUsage Icon { get; init; }
|
|
public Color4? TextColour { get; init; }
|
|
|
|
public OptionButton()
|
|
{
|
|
Size = new Vector2(265, 50);
|
|
}
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load(OverlayColourProvider colourProvider)
|
|
{
|
|
BackgroundColour = colourProvider.Background3;
|
|
|
|
SpriteText.Colour = TextColour ?? Color4.White;
|
|
Content.CornerRadius = 10;
|
|
|
|
Add(new SpriteIcon
|
|
{
|
|
Anchor = Anchor.CentreLeft,
|
|
Origin = Anchor.CentreLeft,
|
|
Size = new Vector2(17),
|
|
X = 15,
|
|
Icon = Icon,
|
|
Colour = TextColour ?? Color4.White,
|
|
});
|
|
}
|
|
|
|
protected override SpriteText CreateText() => new OsuSpriteText
|
|
{
|
|
Depth = -1,
|
|
Origin = Anchor.CentreLeft,
|
|
Anchor = Anchor.CentreLeft,
|
|
X = 40
|
|
};
|
|
}
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
|
{
|
|
// don't absorb control as ToolbarRulesetSelector uses control + number to navigate
|
|
if (e.ControlPressed) return false;
|
|
|
|
if (!e.Repeat && e.Key >= Key.Number1 && e.Key <= Key.Number9)
|
|
{
|
|
int requested = e.Key - Key.Number1;
|
|
|
|
OptionButton? found = buttonFlow.Children.OfType<OptionButton>().ElementAtOrDefault(requested);
|
|
|
|
if (found != null)
|
|
{
|
|
found.TriggerClick();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return base.OnKeyDown(e);
|
|
}
|
|
|
|
protected override void UpdateState(ValueChangedEvent<Visibility> state)
|
|
{
|
|
base.UpdateState(state);
|
|
footerButton.OverlayState.Value = state.NewValue;
|
|
}
|
|
}
|
|
}
|
|
}
|