1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 00:47:24 +08:00

Refactor into a method rather than property

This commit is contained in:
Dean Herbert 2023-02-02 14:53:58 +09:00
parent 942e7729f3
commit 500e9c7944
3 changed files with 15 additions and 13 deletions

View File

@ -47,7 +47,7 @@ namespace osu.Game.Screens.Select.Carousel
private Sprite background = null!;
private MenuItem[]? customMenuItems;
private MenuItem[]? mainMenuItems;
private Action<BeatmapInfo>? selectRequested;
private Action<BeatmapInfo>? hideRequested;
@ -85,7 +85,7 @@ namespace osu.Game.Screens.Select.Carousel
if (songSelect != null)
{
customMenuItems = songSelect.CustomMenuItems.Select(f => f.Invoke(beatmapInfo)).ToArray();
mainMenuItems = songSelect.CreateMenuItemsForBeatmap(beatmapInfo);
selectRequested = b => songSelect.FinaliseSelection(b);
}
@ -227,8 +227,8 @@ namespace osu.Game.Screens.Select.Carousel
{
List<MenuItem> items = new List<MenuItem>();
if (customMenuItems != null)
items.AddRange(customMenuItems);
if (mainMenuItems != null)
items.AddRange(mainMenuItems);
if (beatmapInfo.OnlineID > 0 && beatmapOverlay != null)
items.Add(new OsuMenuItem("Details...", MenuItemType.Standard, () => beatmapOverlay.FetchAndShowBeatmap(beatmapInfo.OnlineID)));

View File

@ -1,7 +1,6 @@
// 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.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
@ -12,9 +11,9 @@ using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
using osu.Game.Screens.Play;
@ -22,6 +21,7 @@ using osu.Game.Screens.Ranking;
using osu.Game.Users;
using osu.Game.Utils;
using osuTK.Input;
using NotificationsStrings = osu.Game.Localisation.NotificationsStrings;
namespace osu.Game.Screens.Select
{
@ -34,12 +34,11 @@ namespace osu.Game.Screens.Select
public override bool AllowExternalScreenChange => true;
public override Func<BeatmapInfo, MenuItem>[] CustomMenuItems =>
new Func<BeatmapInfo, MenuItem>[]
{
b => new OsuMenuItem("Play", MenuItemType.Highlighted, () => FinaliseSelection(b)),
b => new OsuMenuItem(Resources.Localisation.Web.CommonStrings.ButtonsEdit, MenuItemType.Standard, () => Edit(b))
};
public override MenuItem[] CreateMenuItemsForBeatmap(BeatmapInfo b) => new MenuItem[]
{
new OsuMenuItem("Play", MenuItemType.Highlighted, () => FinaliseSelection(b)),
new OsuMenuItem(CommonStrings.ButtonsEdit, MenuItemType.Standard, () => Edit(b))
};
protected override UserActivity InitialActivity => new UserActivity.ChoosingBeatmap();

View File

@ -84,7 +84,10 @@ namespace osu.Game.Screens.Select
public bool BeatmapSetsLoaded => IsLoaded && Carousel.BeatmapSetsLoaded;
public virtual Func<BeatmapInfo, MenuItem>[] CustomMenuItems => new Func<BeatmapInfo, MenuItem>[] { b => new OsuMenuItem(@"Select", MenuItemType.Highlighted, () => FinaliseSelection(b)) };
public virtual MenuItem[] CreateMenuItemsForBeatmap(BeatmapInfo b) => new MenuItem[]
{
new OsuMenuItem(@"Select", MenuItemType.Highlighted, () => FinaliseSelection(b))
};
[Resolved]
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;