2023-09-04 12:49:29 +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 System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2023-09-06 09:43:42 +08:00
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
2023-09-04 12:49:29 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Framework.Localisation;
|
2023-09-05 15:44:55 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2023-09-04 12:49:29 +08:00
|
|
|
using osu.Game.Collections;
|
|
|
|
using osu.Game.Graphics;
|
2023-09-05 15:44:55 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2023-09-04 12:49:29 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
2023-09-06 14:00:07 +08:00
|
|
|
using osu.Game.Localisation;
|
2023-09-04 12:49:29 +08:00
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
using osuTK.Input;
|
2023-09-06 14:00:07 +08:00
|
|
|
using WebCommonStrings = osu.Game.Resources.Localisation.Web.CommonStrings;
|
2023-09-04 12:49:29 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select.FooterV2
|
|
|
|
{
|
|
|
|
public partial class BeatmapOptionsPopover : OsuPopover
|
|
|
|
{
|
2023-09-05 15:44:55 +08:00
|
|
|
private FillFlowContainer buttonFlow = null!;
|
2023-09-04 12:49:29 +08:00
|
|
|
private readonly FooterButtonOptionsV2 footerButton;
|
|
|
|
|
2023-09-05 15:44:55 +08:00
|
|
|
private WorkingBeatmap beatmapWhenOpening = null!;
|
|
|
|
|
2023-09-06 09:18:45 +08:00
|
|
|
[Resolved]
|
|
|
|
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
|
|
|
|
|
2023-09-04 12:49:29 +08:00
|
|
|
public BeatmapOptionsPopover(FooterButtonOptionsV2 footerButton)
|
|
|
|
{
|
|
|
|
this.footerButton = footerButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2023-09-06 09:50:24 +08:00
|
|
|
private void load(ManageCollectionsDialog? manageCollectionsDialog, SongSelect? songSelect, OsuColour colours, BeatmapManager? beatmapManager)
|
2023-09-04 12:49:29 +08:00
|
|
|
{
|
|
|
|
Content.Padding = new MarginPadding(5);
|
|
|
|
|
2023-09-05 15:44:55 +08:00
|
|
|
Child = buttonFlow = new FillFlowContainer
|
2023-09-04 12:49:29 +08:00
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(3),
|
|
|
|
};
|
|
|
|
|
2023-09-05 15:44:55 +08:00
|
|
|
beatmapWhenOpening = beatmap.Value;
|
|
|
|
|
2023-09-06 14:00:07 +08:00
|
|
|
addHeader(CommonStrings.General);
|
2023-09-06 09:43:42 +08:00
|
|
|
addButton(SongSelectStrings.ManageCollections, FontAwesome.Solid.Book, () => manageCollectionsDialog?.Show());
|
2023-09-05 15:44:55 +08:00
|
|
|
|
2023-09-06 09:43:42 +08:00
|
|
|
addHeader(SongSelectStrings.ForAllDifficulties, beatmapWhenOpening.BeatmapSetInfo.ToString());
|
|
|
|
addButton(SongSelectStrings.DeleteBeatmap, FontAwesome.Solid.Trash, () => songSelect?.DeleteBeatmap(beatmapWhenOpening.BeatmapSetInfo), colours.Red1);
|
2023-09-05 15:44:55 +08:00
|
|
|
|
2023-09-06 09:43:42 +08:00
|
|
|
addHeader(SongSelectStrings.ForSelectedDifficulty, beatmapWhenOpening.BeatmapInfo.DifficultyName);
|
2023-09-05 15:44:55 +08:00
|
|
|
// TODO: make work, and make show "unplayed" or "played" based on status.
|
2023-09-06 09:43:42 +08:00
|
|
|
addButton(SongSelectStrings.MarkAsPlayed, FontAwesome.Regular.TimesCircle, null);
|
|
|
|
addButton(SongSelectStrings.ClearAllLocalScores, FontAwesome.Solid.Eraser, () => songSelect?.ClearScores(beatmapWhenOpening.BeatmapInfo), colours.Red1);
|
2023-09-04 12:49:29 +08:00
|
|
|
|
|
|
|
if (songSelect != null && songSelect.AllowEditing)
|
2023-09-06 09:43:42 +08:00
|
|
|
addButton(SongSelectStrings.EditBeatmap, FontAwesome.Solid.PencilAlt, () => songSelect.Edit(beatmapWhenOpening.BeatmapInfo));
|
2023-09-06 09:50:24 +08:00
|
|
|
|
2023-09-06 14:00:07 +08:00
|
|
|
addButton(WebCommonStrings.ButtonsHide.ToSentence(), FontAwesome.Solid.Magic, () => beatmapManager?.Hide(beatmapWhenOpening.BeatmapInfo));
|
2023-09-04 12:49:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
ScheduleAfterChildren(() => GetContainingInputManager().ChangeFocus(this));
|
2023-09-06 09:18:45 +08:00
|
|
|
|
|
|
|
beatmap.BindValueChanged(_ => Hide());
|
2023-09-04 12:49:29 +08:00
|
|
|
}
|
|
|
|
|
2023-09-05 15:44:55 +08:00
|
|
|
[Resolved]
|
|
|
|
private OverlayColourProvider overlayColourProvider { get; set; } = null!;
|
|
|
|
|
2023-09-06 09:43:42 +08:00
|
|
|
private void addHeader(LocalisableString text, string? context = null)
|
2023-09-05 15:44:55 +08:00
|
|
|
{
|
|
|
|
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 = overlayColourProvider.Content2;
|
|
|
|
t.Font = t.Font.With(size: 13);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
buttonFlow.Add(textFlow);
|
|
|
|
}
|
|
|
|
|
2023-09-04 12:49:29 +08:00
|
|
|
private void addButton(LocalisableString text, IconUsage icon, Action? action, Color4? colour = null)
|
|
|
|
{
|
|
|
|
var button = new OptionButton
|
|
|
|
{
|
|
|
|
Text = text,
|
|
|
|
Icon = icon,
|
|
|
|
TextColour = colour,
|
|
|
|
Action = () =>
|
|
|
|
{
|
2023-09-05 15:14:01 +08:00
|
|
|
Scheduler.AddDelayed(Hide, 50);
|
2023-09-04 12:49:29 +08:00
|
|
|
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;
|
|
|
|
|
2023-09-05 15:44:55 +08:00
|
|
|
OptionButton? found = buttonFlow.Children.OfType<OptionButton>().ElementAtOrDefault(requested);
|
2023-09-04 12:49:29 +08:00
|
|
|
|
|
|
|
if (found != null)
|
|
|
|
{
|
|
|
|
found.TriggerClick();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.OnKeyDown(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UpdateState(ValueChangedEvent<Visibility> state)
|
|
|
|
{
|
|
|
|
base.UpdateState(state);
|
|
|
|
|
|
|
|
if (state.NewValue == Visibility.Hidden)
|
|
|
|
footerButton.IsActive.Value = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|