2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-01-10 06:18:47 +08:00
|
|
|
using System;
|
2019-04-03 21:44:36 +08:00
|
|
|
using System.Collections.Generic;
|
2020-09-02 20:08:31 +08:00
|
|
|
using System.Linq;
|
2020-07-16 20:08:24 +08:00
|
|
|
using System.Threading;
|
2017-12-12 16:48:38 +08:00
|
|
|
using osu.Framework.Allocation;
|
2020-07-16 20:08:24 +08:00
|
|
|
using osu.Framework.Bindables;
|
2020-03-11 09:18:41 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2022-06-03 11:28:59 +08:00
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
2017-01-10 06:18:47 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-08-30 19:41:53 +08:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2017-12-12 16:48:38 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-01-10 06:18:47 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2017-12-12 16:48:38 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-10-02 11:02:47 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2017-12-12 16:48:38 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
2020-09-02 20:08:31 +08:00
|
|
|
using osu.Game.Collections;
|
2022-07-27 14:59:36 +08:00
|
|
|
using osu.Game.Database;
|
2017-01-10 06:18:47 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Backgrounds;
|
2017-12-12 16:48:38 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-01-10 06:18:47 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2024-08-20 22:48:11 +08:00
|
|
|
using osu.Game.Online.API;
|
2018-04-18 12:08:53 +08:00
|
|
|
using osu.Game.Overlays;
|
2022-01-28 12:53:48 +08:00
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2023-12-09 21:09:49 +08:00
|
|
|
using osu.Game.Rulesets;
|
2024-03-28 21:39:15 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
2017-01-10 06:18:47 +08:00
|
|
|
{
|
2017-12-12 16:48:38 +08:00
|
|
|
public partial class DrawableCarouselBeatmap : DrawableCarouselItem, IHasContextMenu
|
2017-01-10 06:18:47 +08:00
|
|
|
{
|
2020-10-12 19:26:20 +08:00
|
|
|
public const float CAROUSEL_BEATMAP_SPACING = 5;
|
|
|
|
|
2020-10-13 17:13:36 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The height of a carousel beatmap, including vertical spacing.
|
|
|
|
/// </summary>
|
2022-02-05 15:12:58 +08:00
|
|
|
public const float HEIGHT = height + CAROUSEL_BEATMAP_SPACING;
|
2020-10-13 17:13:36 +08:00
|
|
|
|
2022-02-05 15:12:58 +08:00
|
|
|
private const float height = MAX_HEIGHT * 0.6f;
|
2020-10-12 11:37:41 +08:00
|
|
|
|
2021-10-02 23:55:29 +08:00
|
|
|
private readonly BeatmapInfo beatmapInfo;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2023-01-09 02:02:48 +08:00
|
|
|
private Sprite background = null!;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2023-02-02 13:53:58 +08:00
|
|
|
private MenuItem[]? mainMenuItems;
|
2022-10-13 01:04:45 +08:00
|
|
|
|
2023-01-16 08:09:04 +08:00
|
|
|
private Action<BeatmapInfo>? selectRequested;
|
|
|
|
private Action<BeatmapInfo>? hideRequested;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2023-01-09 02:02:48 +08:00
|
|
|
private Triangles triangles = null!;
|
2022-06-24 13:22:38 +08:00
|
|
|
|
2023-01-09 02:02:48 +08:00
|
|
|
private StarCounter starCounter = null!;
|
|
|
|
private DifficultyIcon difficultyIcon = null!;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2023-12-09 21:09:49 +08:00
|
|
|
private OsuSpriteText keyCountText = null!;
|
|
|
|
|
2023-01-09 02:02:48 +08:00
|
|
|
[Resolved]
|
|
|
|
private BeatmapSetOverlay? beatmapOverlay { get; set; }
|
2018-04-18 12:08:53 +08:00
|
|
|
|
2020-07-16 20:08:24 +08:00
|
|
|
[Resolved]
|
2023-01-09 02:02:48 +08:00
|
|
|
private BeatmapDifficultyCache difficultyCache { get; set; } = null!;
|
2020-07-16 20:08:24 +08:00
|
|
|
|
2023-01-09 02:02:48 +08:00
|
|
|
[Resolved]
|
|
|
|
private ManageCollectionsDialog? manageCollectionsDialog { get; set; }
|
2020-09-05 02:52:07 +08:00
|
|
|
|
2022-07-27 14:59:36 +08:00
|
|
|
[Resolved]
|
2023-01-09 02:02:48 +08:00
|
|
|
private RealmAccess realm { get; set; } = null!;
|
2022-07-27 14:59:36 +08:00
|
|
|
|
2023-12-09 21:09:49 +08:00
|
|
|
[Resolved]
|
|
|
|
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
|
|
|
|
|
2024-03-28 21:39:15 +08:00
|
|
|
[Resolved]
|
2024-03-28 22:02:25 +08:00
|
|
|
private IBindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
|
2024-03-28 21:39:15 +08:00
|
|
|
|
2024-08-22 01:08:01 +08:00
|
|
|
[Resolved]
|
2024-08-22 12:43:10 +08:00
|
|
|
private IAPIProvider api { get; set; } = null!;
|
2024-08-22 01:08:01 +08:00
|
|
|
|
|
|
|
[Resolved]
|
2024-08-22 12:43:10 +08:00
|
|
|
private OsuGame? game { get; set; }
|
2024-08-22 01:08:01 +08:00
|
|
|
|
2023-01-09 02:02:48 +08:00
|
|
|
private IBindable<StarDifficulty?> starDifficultyBindable = null!;
|
|
|
|
private CancellationTokenSource? starDifficultyCancellationSource;
|
2020-07-21 22:13:04 +08:00
|
|
|
|
2019-02-28 12:31:40 +08:00
|
|
|
public DrawableCarouselBeatmap(CarouselBeatmap panel)
|
2017-12-15 17:38:09 +08:00
|
|
|
{
|
2021-10-02 23:55:29 +08:00
|
|
|
beatmapInfo = panel.BeatmapInfo;
|
2020-10-12 14:36:03 +08:00
|
|
|
Item = panel;
|
2017-12-15 17:38:09 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2023-01-09 02:02:48 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2024-08-22 01:17:11 +08:00
|
|
|
private void load(BeatmapManager? manager, SongSelect? songSelect)
|
2017-02-24 18:30:04 +08:00
|
|
|
{
|
2022-02-05 15:12:58 +08:00
|
|
|
Header.Height = height;
|
|
|
|
|
2017-12-13 18:56:16 +08:00
|
|
|
if (songSelect != null)
|
|
|
|
{
|
2023-12-19 18:58:49 +08:00
|
|
|
mainMenuItems = songSelect.CreateForwardNavigationMenuItemsForBeatmap(() => beatmapInfo);
|
2022-10-13 01:04:45 +08:00
|
|
|
selectRequested = b => songSelect.FinaliseSelection(b);
|
2017-12-13 18:56:16 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-12-13 18:56:16 +08:00
|
|
|
if (manager != null)
|
2017-12-18 10:13:16 +08:00
|
|
|
hideRequested = manager.Hide;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-10-13 14:19:32 +08:00
|
|
|
Header.Children = new Drawable[]
|
2017-01-10 06:18:47 +08:00
|
|
|
{
|
|
|
|
background = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2017-01-30 15:53:12 +08:00
|
|
|
triangles = new Triangles
|
2016-11-26 16:10:13 +08:00
|
|
|
{
|
2017-02-04 21:09:44 +08:00
|
|
|
TriangleScale = 2,
|
2016-11-26 16:10:13 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-03-11 09:18:41 +08:00
|
|
|
ColourLight = Color4Extensions.FromHex(@"3a7285"),
|
|
|
|
ColourDark = Color4Extensions.FromHex(@"123744")
|
2017-01-10 06:18:47 +08:00
|
|
|
},
|
2017-03-02 02:33:01 +08:00
|
|
|
new FillFlowContainer
|
2017-01-10 06:18:47 +08:00
|
|
|
{
|
|
|
|
Padding = new MarginPadding(5),
|
2017-03-04 18:00:17 +08:00
|
|
|
Direction = FillDirection.Horizontal,
|
2017-01-10 06:18:47 +08:00
|
|
|
AutoSizeAxes = Axes.Both,
|
2016-11-04 17:08:43 +08:00
|
|
|
Anchor = Anchor.CentreLeft,
|
2017-01-10 06:18:47 +08:00
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2022-06-24 13:22:38 +08:00
|
|
|
difficultyIcon = new DifficultyIcon(beatmapInfo)
|
2016-11-04 17:08:43 +08:00
|
|
|
{
|
2024-02-22 18:57:40 +08:00
|
|
|
TooltipType = DifficultyIconTooltipType.None,
|
2016-11-04 17:08:43 +08:00
|
|
|
Scale = new Vector2(1.8f),
|
2017-01-10 06:18:47 +08:00
|
|
|
},
|
2017-03-02 02:33:01 +08:00
|
|
|
new FillFlowContainer
|
2017-01-10 06:18:47 +08:00
|
|
|
{
|
|
|
|
Padding = new MarginPadding { Left = 5 },
|
2017-03-04 18:00:17 +08:00
|
|
|
Direction = FillDirection.Vertical,
|
2017-01-10 06:18:47 +08:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2017-03-02 02:33:01 +08:00
|
|
|
new FillFlowContainer
|
2017-01-10 06:18:47 +08:00
|
|
|
{
|
2017-03-04 18:00:17 +08:00
|
|
|
Direction = FillDirection.Horizontal,
|
2017-03-02 02:33:01 +08:00
|
|
|
Spacing = new Vector2(4, 0),
|
2017-01-10 06:18:47 +08:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Children = new[]
|
|
|
|
{
|
2023-12-09 21:09:49 +08:00
|
|
|
keyCountText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Font = OsuFont.GetFont(size: 20),
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
Alpha = 0,
|
|
|
|
},
|
2017-01-31 17:53:52 +08:00
|
|
|
new OsuSpriteText
|
2017-01-10 06:18:47 +08:00
|
|
|
{
|
2021-11-11 16:19:53 +08:00
|
|
|
Text = beatmapInfo.DifficultyName,
|
2019-02-20 15:52:36 +08:00
|
|
|
Font = OsuFont.GetFont(size: 20),
|
2017-01-10 06:18:47 +08:00
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft
|
|
|
|
},
|
2017-01-31 17:53:52 +08:00
|
|
|
new OsuSpriteText
|
2017-01-10 06:18:47 +08:00
|
|
|
{
|
2022-01-28 12:53:48 +08:00
|
|
|
Text = BeatmapsetsStrings.ShowDetailsMappedBy(beatmapInfo.Metadata.Author.Username),
|
2017-01-10 06:18:47 +08:00
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2020-03-28 23:22:01 +08:00
|
|
|
new FillFlowContainer
|
2017-02-24 18:30:04 +08:00
|
|
|
{
|
2020-03-28 23:22:01 +08:00
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(4, 0),
|
2022-07-18 17:06:11 +08:00
|
|
|
Scale = new Vector2(0.8f),
|
2020-03-28 23:22:01 +08:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2022-07-18 17:06:11 +08:00
|
|
|
new TopLocalRank(beatmapInfo),
|
|
|
|
starCounter = new StarCounter()
|
2020-03-28 23:22:01 +08:00
|
|
|
}
|
2017-02-24 18:30:04 +08:00
|
|
|
}
|
2017-01-10 06:18:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2016-10-27 18:52:48 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2023-12-09 21:09:49 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
ruleset.BindValueChanged(_ => updateKeyCount());
|
2024-03-28 22:02:25 +08:00
|
|
|
mods.BindValueChanged(_ => updateKeyCount());
|
2023-12-09 21:09:49 +08:00
|
|
|
}
|
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
protected override void Selected()
|
|
|
|
{
|
|
|
|
base.Selected();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-10-13 16:33:35 +08:00
|
|
|
MovementContainer.MoveToX(-50, 500, Easing.OutExpo);
|
2020-10-12 13:23:18 +08:00
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
background.Colour = ColourInfo.GradientVertical(
|
|
|
|
new Color4(20, 43, 51, 255),
|
|
|
|
new Color4(40, 86, 102, 255));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
triangles.Colour = Color4.White;
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
protected override void Deselected()
|
|
|
|
{
|
|
|
|
base.Deselected();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-10-13 16:33:35 +08:00
|
|
|
MovementContainer.MoveToX(0, 500, Easing.OutExpo);
|
2020-10-12 17:19:20 +08:00
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
background.Colour = new Color4(20, 43, 51, 255);
|
|
|
|
triangles.Colour = OsuColour.Gray(0.5f);
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
protected override bool OnClick(ClickEvent e)
|
2017-12-12 16:48:38 +08:00
|
|
|
{
|
2023-01-16 08:09:04 +08:00
|
|
|
if (Item?.State.Value == CarouselItemState.Selected)
|
2022-10-13 01:04:45 +08:00
|
|
|
selectRequested?.Invoke(beatmapInfo);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
return base.OnClick(e);
|
2017-12-12 16:48:38 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
protected override void ApplyState()
|
|
|
|
{
|
2023-01-10 01:36:55 +08:00
|
|
|
if (Item?.State.Value != CarouselItemState.Collapsed && Alpha == 0)
|
2017-12-12 16:48:38 +08:00
|
|
|
starCounter.ReplayAnimation();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-07-23 22:18:43 +08:00
|
|
|
starDifficultyCancellationSource?.Cancel();
|
2020-07-21 22:13:04 +08:00
|
|
|
|
2020-07-23 22:18:43 +08:00
|
|
|
// Only compute difficulty when the item is visible.
|
2023-01-10 01:36:55 +08:00
|
|
|
if (Item?.State.Value != CarouselItemState.Collapsed)
|
2020-07-23 22:18:43 +08:00
|
|
|
{
|
2020-07-21 22:13:04 +08:00
|
|
|
// We've potentially cancelled the computation above so a new bindable is required.
|
2021-10-02 23:55:29 +08:00
|
|
|
starDifficultyBindable = difficultyCache.GetBindableDifficulty(beatmapInfo, (starDifficultyCancellationSource = new CancellationTokenSource()).Token);
|
2021-02-25 15:19:01 +08:00
|
|
|
starDifficultyBindable.BindValueChanged(d =>
|
|
|
|
{
|
|
|
|
starCounter.Current = (float)(d.NewValue?.Stars ?? 0);
|
2022-06-24 13:22:38 +08:00
|
|
|
if (d.NewValue != null)
|
|
|
|
difficultyIcon.Current.Value = d.NewValue.Value;
|
2021-02-25 15:19:01 +08:00
|
|
|
}, true);
|
2023-12-09 21:09:49 +08:00
|
|
|
|
|
|
|
updateKeyCount();
|
2020-07-21 22:13:04 +08:00
|
|
|
}
|
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
base.ApplyState();
|
|
|
|
}
|
2019-04-03 22:37:50 +08:00
|
|
|
|
2023-12-09 21:09:49 +08:00
|
|
|
private void updateKeyCount()
|
|
|
|
{
|
2023-12-15 10:01:13 +08:00
|
|
|
if (Item?.State.Value == CarouselItemState.Collapsed)
|
|
|
|
return;
|
|
|
|
|
2023-12-09 21:09:49 +08:00
|
|
|
if (ruleset.Value.OnlineID == 3)
|
|
|
|
{
|
|
|
|
// Account for mania differences locally for now.
|
|
|
|
// Eventually this should be handled in a more modular way, allowing rulesets to add more information to the panel.
|
|
|
|
ILegacyRuleset legacyRuleset = (ILegacyRuleset)ruleset.Value.CreateInstance();
|
|
|
|
|
|
|
|
keyCountText.Alpha = 1;
|
2024-03-28 22:02:25 +08:00
|
|
|
keyCountText.Text = $"[{legacyRuleset.GetKeyCount(beatmapInfo, mods.Value)}K]";
|
2023-12-09 21:09:49 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
keyCountText.Alpha = 0;
|
|
|
|
}
|
|
|
|
|
2019-04-03 21:44:36 +08:00
|
|
|
public MenuItem[] ContextMenuItems
|
2017-08-30 19:41:53 +08:00
|
|
|
{
|
2019-04-03 21:44:36 +08:00
|
|
|
get
|
2018-04-18 12:08:53 +08:00
|
|
|
{
|
2020-04-16 11:10:20 +08:00
|
|
|
List<MenuItem> items = new List<MenuItem>();
|
2019-04-03 22:40:20 +08:00
|
|
|
|
2023-02-02 13:53:58 +08:00
|
|
|
if (mainMenuItems != null)
|
|
|
|
items.AddRange(mainMenuItems);
|
2020-04-16 09:17:12 +08:00
|
|
|
|
2021-11-22 13:55:41 +08:00
|
|
|
if (beatmapInfo.OnlineID > 0 && beatmapOverlay != null)
|
|
|
|
items.Add(new OsuMenuItem("Details...", MenuItemType.Standard, () => beatmapOverlay.FetchAndShowBeatmap(beatmapInfo.OnlineID)));
|
2019-04-03 21:44:36 +08:00
|
|
|
|
2023-10-16 14:53:40 +08:00
|
|
|
var collectionItems = realm.Realm.All<BeatmapCollection>()
|
|
|
|
.OrderBy(c => c.Name)
|
|
|
|
.AsEnumerable()
|
|
|
|
.Select(c => new CollectionToggleMenuItem(c.ToLive(realm), beatmapInfo)).Cast<OsuMenuItem>().ToList();
|
|
|
|
|
2022-07-27 14:59:36 +08:00
|
|
|
if (manageCollectionsDialog != null)
|
|
|
|
collectionItems.Add(new OsuMenuItem("Manage...", MenuItemType.Standard, manageCollectionsDialog.Show));
|
2020-09-05 02:52:07 +08:00
|
|
|
|
2022-07-27 14:59:36 +08:00
|
|
|
items.Add(new OsuMenuItem("Collections") { Items = collectionItems });
|
2020-09-02 20:08:31 +08:00
|
|
|
|
2024-08-22 01:08:01 +08:00
|
|
|
if (beatmapInfo.GetOnlineURL(api) is string url)
|
2024-08-22 12:43:10 +08:00
|
|
|
items.Add(new OsuMenuItem("Copy link", MenuItemType.Standard, () => game?.CopyUrlToClipboard(url)));
|
2024-08-20 22:48:11 +08:00
|
|
|
|
2020-09-08 11:04:35 +08:00
|
|
|
if (hideRequested != null)
|
2022-06-03 11:28:59 +08:00
|
|
|
items.Add(new OsuMenuItem(CommonStrings.ButtonsHide.ToSentence(), MenuItemType.Destructive, () => hideRequested(beatmapInfo)));
|
2020-09-08 11:04:35 +08:00
|
|
|
|
2019-04-03 21:44:36 +08:00
|
|
|
return items.ToArray();
|
|
|
|
}
|
|
|
|
}
|
2020-07-21 22:13:04 +08:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
starDifficultyCancellationSource?.Cancel();
|
|
|
|
}
|
2017-01-10 06:18:47 +08:00
|
|
|
}
|
|
|
|
}
|