Skip to content

Commit

Permalink
Merge pull request #24712 from Joehuu/beatmap-options-popover
Browse files Browse the repository at this point in the history
Implement beatmap options popover
  • Loading branch information
bdach committed Sep 6, 2023
2 parents 1ca713f + dded7fe commit 65e5169
Show file tree
Hide file tree
Showing 16 changed files with 319 additions and 36 deletions.
26 changes: 23 additions & 3 deletions osu.Game.Tests/Visual/SongSelect/TestSceneSongSelectFooterV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
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;

Expand Down Expand Up @@ -37,10 +39,10 @@ public partial class TestSceneSongSelectFooterV2 : OsuManualInputManagerTestScen
Children = new Drawable[]
{
footer = new FooterV2
new PopoverContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
RelativeSizeAxes = Axes.Both,
Child = footer = new FooterV2(),
},
overlay = new DummyOverlay()
};
Expand All @@ -56,6 +58,24 @@ public partial class TestSceneSongSelectFooterV2 : OsuManualInputManagerTestScen
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()
{
Expand Down
5 changes: 5 additions & 0 deletions osu.Game/Localisation/CommonStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ public static class CommonStrings
/// </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}";
}
}
5 changes: 0 additions & 5 deletions osu.Game/Localisation/DebugSettingsStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ public static class DebugSettingsStrings
/// </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>
Expand Down
5 changes: 0 additions & 5 deletions osu.Game/Localisation/GameplaySettingsStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ public static class GameplaySettingsStrings
/// </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>
Expand Down
5 changes: 0 additions & 5 deletions osu.Game/Localisation/GeneralSettingsStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ public static class GeneralSettingsStrings
{
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>
Expand Down
35 changes: 35 additions & 0 deletions osu.Game/Localisation/SongSelectStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,41 @@ public static class SongSelectStrings
/// </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}";
}
}
5 changes: 0 additions & 5 deletions osu.Game/Localisation/UserInterfaceStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ public static class UserInterfaceStrings
/// </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>
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Overlays/OSD/CopyUrlToast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Overlays/Settings/Sections/GeneralSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class GeneralSection : SettingsSection
[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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
196 changes: 196 additions & 0 deletions osu.Game/Screens/Select/FooterV2/BeatmapOptionsPopover.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit 65e5169

Please sign in to comment.