mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 11:37:28 +08:00
Merge pull request #24712 from Joehuu/beatmap-options-popover
Implement beatmap options popover
This commit is contained in:
commit
65e51691ca
@ -6,9 +6,11 @@ using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Mods;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Screens.Select.FooterV2;
|
||||
using osuTK.Input;
|
||||
|
||||
@ -37,10 +39,10 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
footer = new FooterV2
|
||||
new PopoverContainer
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = footer = new FooterV2(),
|
||||
},
|
||||
overlay = new DummyOverlay()
|
||||
};
|
||||
@ -56,6 +58,24 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
overlay.Hide();
|
||||
});
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
AddStep("set beatmap", () => Beatmap.Value = CreateWorkingBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestShowOptions()
|
||||
{
|
||||
AddStep("enable options", () =>
|
||||
{
|
||||
var optionsButton = this.ChildrenOfType<FooterButtonV2>().Last();
|
||||
|
||||
optionsButton.Enabled.Value = true;
|
||||
optionsButton.TriggerClick();
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestState()
|
||||
{
|
||||
|
@ -169,6 +169,11 @@ namespace osu.Game.Localisation
|
||||
/// </summary>
|
||||
public static LocalisableString RevertToDefault => new TranslatableString(getKey(@"revert_to_default"), @"Revert to default");
|
||||
|
||||
/// <summary>
|
||||
/// "General"
|
||||
/// </summary>
|
||||
public static LocalisableString General => new TranslatableString(getKey(@"general"), @"General");
|
||||
|
||||
private static string getKey(string key) => $@"{prefix}:{key}";
|
||||
}
|
||||
}
|
||||
|
@ -14,11 +14,6 @@ namespace osu.Game.Localisation
|
||||
/// </summary>
|
||||
public static LocalisableString DebugSectionHeader => new TranslatableString(getKey(@"debug_section_header"), @"Debug");
|
||||
|
||||
/// <summary>
|
||||
/// "General"
|
||||
/// </summary>
|
||||
public static LocalisableString GeneralHeader => new TranslatableString(getKey(@"general_header"), @"General");
|
||||
|
||||
/// <summary>
|
||||
/// "Show log overlay"
|
||||
/// </summary>
|
||||
|
@ -19,11 +19,6 @@ namespace osu.Game.Localisation
|
||||
/// </summary>
|
||||
public static LocalisableString BeatmapHeader => new TranslatableString(getKey(@"beatmap_header"), @"Beatmap");
|
||||
|
||||
/// <summary>
|
||||
/// "General"
|
||||
/// </summary>
|
||||
public static LocalisableString GeneralHeader => new TranslatableString(getKey(@"general_header"), @"General");
|
||||
|
||||
/// <summary>
|
||||
/// "Audio"
|
||||
/// </summary>
|
||||
|
@ -9,11 +9,6 @@ namespace osu.Game.Localisation
|
||||
{
|
||||
private const string prefix = @"osu.Game.Resources.Localisation.GeneralSettings";
|
||||
|
||||
/// <summary>
|
||||
/// "General"
|
||||
/// </summary>
|
||||
public static LocalisableString GeneralSectionHeader => new TranslatableString(getKey(@"general_section_header"), @"General");
|
||||
|
||||
/// <summary>
|
||||
/// "Language"
|
||||
/// </summary>
|
||||
|
@ -19,6 +19,41 @@ namespace osu.Game.Localisation
|
||||
/// </summary>
|
||||
public static LocalisableString LocallyModifiedTooltip => new TranslatableString(getKey(@"locally_modified_tooltip"), @"Has been locally modified");
|
||||
|
||||
/// <summary>
|
||||
/// "Manage collections"
|
||||
/// </summary>
|
||||
public static LocalisableString ManageCollections => new TranslatableString(getKey(@"manage_collections"), @"Manage collections");
|
||||
|
||||
/// <summary>
|
||||
/// "For all difficulties"
|
||||
/// </summary>
|
||||
public static LocalisableString ForAllDifficulties => new TranslatableString(getKey(@"for_all_difficulties"), @"For all difficulties");
|
||||
|
||||
/// <summary>
|
||||
/// "Delete beatmap"
|
||||
/// </summary>
|
||||
public static LocalisableString DeleteBeatmap => new TranslatableString(getKey(@"delete_beatmap"), @"Delete beatmap");
|
||||
|
||||
/// <summary>
|
||||
/// "For selected difficulty"
|
||||
/// </summary>
|
||||
public static LocalisableString ForSelectedDifficulty => new TranslatableString(getKey(@"for_selected_difficulty"), @"For selected difficulty");
|
||||
|
||||
/// <summary>
|
||||
/// "Mark as played"
|
||||
/// </summary>
|
||||
public static LocalisableString MarkAsPlayed => new TranslatableString(getKey(@"mark_as_played"), @"Mark as played");
|
||||
|
||||
/// <summary>
|
||||
/// "Clear all local scores"
|
||||
/// </summary>
|
||||
public static LocalisableString ClearAllLocalScores => new TranslatableString(getKey(@"clear_all_local_scores"), @"Clear all local scores");
|
||||
|
||||
/// <summary>
|
||||
/// "Edit beatmap"
|
||||
/// </summary>
|
||||
public static LocalisableString EditBeatmap => new TranslatableString(getKey(@"edit_beatmap"), @"Edit beatmap");
|
||||
|
||||
private static string getKey(string key) => $@"{prefix}:{key}";
|
||||
}
|
||||
}
|
||||
|
@ -14,11 +14,6 @@ namespace osu.Game.Localisation
|
||||
/// </summary>
|
||||
public static LocalisableString UserInterfaceSectionHeader => new TranslatableString(getKey(@"user_interface_section_header"), @"User Interface");
|
||||
|
||||
/// <summary>
|
||||
/// "General"
|
||||
/// </summary>
|
||||
public static LocalisableString GeneralHeader => new TranslatableString(getKey(@"general_header"), @"General");
|
||||
|
||||
/// <summary>
|
||||
/// "Rotate cursor when dragging"
|
||||
/// </summary>
|
||||
|
@ -8,7 +8,7 @@ namespace osu.Game.Overlays.OSD
|
||||
public partial class CopyUrlToast : Toast
|
||||
{
|
||||
public CopyUrlToast()
|
||||
: base(UserInterfaceStrings.GeneralHeader, ToastStrings.UrlCopied, "")
|
||||
: base(CommonStrings.General, ToastStrings.UrlCopied, "")
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace osu.Game.Overlays.Settings.Sections.DebugSettings
|
||||
{
|
||||
public partial class GeneralSettings : SettingsSubsection
|
||||
{
|
||||
protected override LocalisableString Header => DebugSettingsStrings.GeneralHeader;
|
||||
protected override LocalisableString Header => CommonStrings.General;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(FrameworkDebugConfigManager config, FrameworkConfigManager frameworkConfig, IPerformFromScreenRunner? performer)
|
||||
|
@ -12,7 +12,7 @@ namespace osu.Game.Overlays.Settings.Sections.Gameplay
|
||||
{
|
||||
public partial class GeneralSettings : SettingsSubsection
|
||||
{
|
||||
protected override LocalisableString Header => GameplaySettingsStrings.GeneralHeader;
|
||||
protected override LocalisableString Header => CommonStrings.General;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config)
|
||||
|
@ -19,7 +19,7 @@ namespace osu.Game.Overlays.Settings.Sections
|
||||
[Resolved(CanBeNull = true)]
|
||||
private OsuGame? game { get; set; }
|
||||
|
||||
public override LocalisableString Header => GeneralSettingsStrings.GeneralSectionHeader;
|
||||
public override LocalisableString Header => CommonStrings.General;
|
||||
|
||||
public override Drawable CreateIcon() => new SpriteIcon
|
||||
{
|
||||
|
@ -12,7 +12,7 @@ namespace osu.Game.Overlays.Settings.Sections.UserInterface
|
||||
{
|
||||
public partial class GeneralSettings : SettingsSubsection
|
||||
{
|
||||
protected override LocalisableString Header => UserInterfaceStrings.GeneralHeader;
|
||||
protected override LocalisableString Header => CommonStrings.General;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config)
|
||||
|
196
osu.Game/Screens/Select/FooterV2/BeatmapOptionsPopover.cs
Normal file
196
osu.Game/Screens/Select/FooterV2/BeatmapOptionsPopover.cs
Normal file
@ -0,0 +1,196 @@
|
||||
// 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.Select.FooterV2
|
||||
{
|
||||
public partial class BeatmapOptionsPopover : OsuPopover
|
||||
{
|
||||
private FillFlowContainer buttonFlow = null!;
|
||||
private readonly FooterButtonOptionsV2 footerButton;
|
||||
|
||||
private WorkingBeatmap beatmapWhenOpening = null!;
|
||||
|
||||
[Resolved]
|
||||
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
|
||||
|
||||
public BeatmapOptionsPopover(FooterButtonOptionsV2 footerButton)
|
||||
{
|
||||
this.footerButton = footerButton;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(ManageCollectionsDialog? manageCollectionsDialog, SongSelect? songSelect, 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, () => songSelect?.DeleteBeatmap(beatmapWhenOpening.BeatmapSetInfo), colours.Red1);
|
||||
|
||||
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, () => songSelect?.ClearScores(beatmapWhenOpening.BeatmapInfo), colours.Red1);
|
||||
|
||||
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(() => GetContainingInputManager().ChangeFocus(this));
|
||||
|
||||
beatmap.BindValueChanged(_ => Hide());
|
||||
}
|
||||
|
||||
[Resolved]
|
||||
private OverlayColourProvider overlayColourProvider { get; set; } = null!;
|
||||
|
||||
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 = overlayColourProvider.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);
|
||||
|
||||
if (state.NewValue == Visibility.Hidden)
|
||||
footerButton.IsActive.Value = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -2,14 +2,21 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Input.Bindings;
|
||||
|
||||
namespace osu.Game.Screens.Select.FooterV2
|
||||
{
|
||||
public partial class FooterButtonOptionsV2 : FooterButtonV2
|
||||
public partial class FooterButtonOptionsV2 : FooterButtonV2, IHasPopover
|
||||
{
|
||||
public readonly BindableBool IsActive = new BindableBool();
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colour)
|
||||
{
|
||||
@ -17,6 +24,34 @@ namespace osu.Game.Screens.Select.FooterV2
|
||||
Icon = FontAwesome.Solid.Cog;
|
||||
AccentColour = colour.Purple1;
|
||||
Hotkey = GlobalAction.ToggleBeatmapOptions;
|
||||
|
||||
Action = () => IsActive.Toggle();
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
IsActive.BindValueChanged(active =>
|
||||
{
|
||||
OverlayState.Value = active.NewValue ? Visibility.Visible : Visibility.Hidden;
|
||||
});
|
||||
|
||||
OverlayState.BindValueChanged(state =>
|
||||
{
|
||||
switch (state.NewValue)
|
||||
{
|
||||
case Visibility.Hidden:
|
||||
this.HidePopover();
|
||||
break;
|
||||
|
||||
case Visibility.Visible:
|
||||
this.ShowPopover();
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Popover GetPopover() => new BeatmapOptionsPopover(this);
|
||||
}
|
||||
}
|
||||
|
@ -48,11 +48,17 @@ namespace osu.Game.Screens.Select.FooterV2
|
||||
|
||||
private FillFlowContainer<FooterButtonV2> buttons = null!;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OverlayColourProvider colourProvider)
|
||||
public FooterV2()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = height;
|
||||
Anchor = Anchor.BottomLeft;
|
||||
Origin = Anchor.BottomLeft;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OverlayColourProvider colourProvider)
|
||||
{
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
|
@ -311,9 +311,9 @@ namespace osu.Game.Screens.Select
|
||||
Footer.AddButton(button, overlay);
|
||||
|
||||
BeatmapOptions.AddButton(@"Manage", @"collections", FontAwesome.Solid.Book, colours.Green, () => manageCollectionsDialog?.Show());
|
||||
BeatmapOptions.AddButton(@"Delete", @"all difficulties", FontAwesome.Solid.Trash, colours.Pink, () => delete(Beatmap.Value.BeatmapSetInfo));
|
||||
BeatmapOptions.AddButton(@"Delete", @"all difficulties", FontAwesome.Solid.Trash, colours.Pink, () => DeleteBeatmap(Beatmap.Value.BeatmapSetInfo));
|
||||
BeatmapOptions.AddButton(@"Remove", @"from unplayed", FontAwesome.Regular.TimesCircle, colours.Purple, null);
|
||||
BeatmapOptions.AddButton(@"Clear", @"local scores", FontAwesome.Solid.Eraser, colours.Purple, () => clearScores(Beatmap.Value.BeatmapInfo));
|
||||
BeatmapOptions.AddButton(@"Clear", @"local scores", FontAwesome.Solid.Eraser, colours.Purple, () => ClearScores(Beatmap.Value.BeatmapInfo));
|
||||
}
|
||||
|
||||
sampleChangeDifficulty = audio.Samples.Get(@"SongSelect/select-difficulty");
|
||||
@ -916,14 +916,20 @@ namespace osu.Game.Screens.Select
|
||||
return true;
|
||||
}
|
||||
|
||||
private void delete(BeatmapSetInfo? beatmap)
|
||||
/// <summary>
|
||||
/// Request to delete a specific beatmap.
|
||||
/// </summary>
|
||||
public void DeleteBeatmap(BeatmapSetInfo? beatmap)
|
||||
{
|
||||
if (beatmap == null) return;
|
||||
|
||||
dialogOverlay?.Push(new BeatmapDeleteDialog(beatmap));
|
||||
}
|
||||
|
||||
private void clearScores(BeatmapInfo? beatmapInfo)
|
||||
/// <summary>
|
||||
/// Request to clear the scores of a specific beatmap.
|
||||
/// </summary>
|
||||
public void ClearScores(BeatmapInfo? beatmapInfo)
|
||||
{
|
||||
if (beatmapInfo == null) return;
|
||||
|
||||
@ -963,7 +969,7 @@ namespace osu.Game.Screens.Select
|
||||
if (e.ShiftPressed)
|
||||
{
|
||||
if (!Beatmap.IsDefault)
|
||||
delete(Beatmap.Value.BeatmapSetInfo);
|
||||
DeleteBeatmap(Beatmap.Value.BeatmapSetInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user