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
|
|
|
|
2019-12-30 03:19:46 +08:00
|
|
|
using System;
|
2018-04-13 17:19:50 +08:00
|
|
|
using System.Collections.Generic;
|
2019-06-27 11:00:31 +08:00
|
|
|
using System.Diagnostics;
|
2018-04-13 17:19:50 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-12-30 03:19:46 +08:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2019-04-02 13:51:28 +08:00
|
|
|
using osu.Framework.Graphics.Effects;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2019-12-30 03:19:46 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-10-02 11:02:47 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2018-05-25 05:37:53 +08:00
|
|
|
using osu.Game.Audio;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
|
|
|
using osu.Game.Graphics;
|
2019-12-30 03:19:46 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2019-12-30 03:19:46 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-04-21 15:03:18 +08:00
|
|
|
namespace osu.Game.Overlays.BeatmapListing.Panels
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2020-04-21 15:03:18 +08:00
|
|
|
public abstract class BeatmapPanel : OsuClickableContainer, IHasContextMenu
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
public readonly BeatmapSetInfo SetInfo;
|
|
|
|
|
|
|
|
private const double hover_transition_time = 400;
|
2019-09-03 02:00:12 +08:00
|
|
|
private const int maximum_difficulty_icons = 10;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
private Container content;
|
|
|
|
|
2018-05-25 05:37:53 +08:00
|
|
|
public PreviewTrack Preview => PlayButton.Preview;
|
2019-09-02 16:12:32 +08:00
|
|
|
public Bindable<bool> PreviewPlaying => PlayButton?.Playing;
|
2019-06-27 03:42:34 +08:00
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
protected abstract PlayButton PlayButton { get; }
|
|
|
|
protected abstract Box PreviewBar { get; }
|
|
|
|
|
2018-08-05 13:36:09 +08:00
|
|
|
protected virtual bool FadePlayButton => true;
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
2019-12-30 03:19:46 +08:00
|
|
|
protected Action ViewBeatmap;
|
|
|
|
|
2020-04-21 15:03:18 +08:00
|
|
|
protected BeatmapPanel(BeatmapSetInfo setInfo)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2019-06-27 11:00:31 +08:00
|
|
|
Debug.Assert(setInfo.OnlineBeatmapSetID != null);
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
SetInfo = setInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
private readonly EdgeEffectParameters edgeEffectNormal = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Offset = new Vector2(0f, 1f),
|
|
|
|
Radius = 2f,
|
|
|
|
Colour = Color4.Black.Opacity(0.25f),
|
|
|
|
};
|
|
|
|
|
|
|
|
private readonly EdgeEffectParameters edgeEffectHovered = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Offset = new Vector2(0f, 5f),
|
|
|
|
Radius = 10f,
|
|
|
|
Colour = Color4.Black.Opacity(0.3f),
|
|
|
|
};
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader(permitNulls: true)]
|
2019-08-24 06:30:33 +08:00
|
|
|
private void load(BeatmapManager beatmaps, OsuColour colours, BeatmapSetOverlay beatmapSetOverlay)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
AddInternal(content = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Masking = true,
|
|
|
|
EdgeEffect = edgeEffectNormal,
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
CreateBackground(),
|
2019-01-17 20:10:34 +08:00
|
|
|
new DownloadProgressBar(SetInfo)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
Depth = -1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
2019-12-30 03:19:46 +08:00
|
|
|
|
|
|
|
Action = ViewBeatmap = () =>
|
|
|
|
{
|
|
|
|
Debug.Assert(SetInfo.OnlineBeatmapSetID != null);
|
|
|
|
beatmapSetOverlay?.FetchAndShowBeatmapSet(SetInfo.OnlineBeatmapSetID.Value);
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
if (PreviewPlaying.Value && Preview != null && Preview.TrackLoaded)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2018-06-21 15:19:07 +08:00
|
|
|
PreviewBar.Width = (float)(Preview.CurrentTime / Preview.Length);
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
content.TweenEdgeEffectTo(edgeEffectHovered, hover_transition_time, Easing.OutQuint);
|
|
|
|
content.MoveToY(-4, hover_transition_time, Easing.OutQuint);
|
2018-08-05 13:36:09 +08:00
|
|
|
if (FadePlayButton)
|
2018-08-08 14:49:27 +08:00
|
|
|
PlayButton.FadeIn(120, Easing.InOutQuint);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
return base.OnHover(e);
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
content.TweenEdgeEffectTo(edgeEffectNormal, hover_transition_time, Easing.OutQuint);
|
|
|
|
content.MoveToY(0, hover_transition_time, Easing.OutQuint);
|
2019-02-21 17:56:34 +08:00
|
|
|
if (FadePlayButton && !PreviewPlaying.Value)
|
2018-04-13 17:19:50 +08:00
|
|
|
PlayButton.FadeOut(120, Easing.InOutQuint);
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
base.OnHoverLost(e);
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
this.FadeInFromZero(200, Easing.Out);
|
|
|
|
|
2019-02-22 16:51:39 +08:00
|
|
|
PreviewPlaying.ValueChanged += playing =>
|
|
|
|
{
|
|
|
|
PlayButton.FadeTo(playing.NewValue || IsHovered || !FadePlayButton ? 1 : 0, 120, Easing.InOutQuint);
|
|
|
|
PreviewBar.FadeTo(playing.NewValue ? 1 : 0, 120, Easing.InOutQuint);
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
2019-08-25 10:44:56 +08:00
|
|
|
protected List<DifficultyIcon> GetDifficultyIcons(OsuColour colours)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
var icons = new List<DifficultyIcon>();
|
|
|
|
|
2019-08-24 04:40:41 +08:00
|
|
|
if (SetInfo.Beatmaps.Count > maximum_difficulty_icons)
|
|
|
|
{
|
2019-08-24 06:30:33 +08:00
|
|
|
foreach (var ruleset in SetInfo.Beatmaps.Select(b => b.Ruleset).Distinct())
|
2020-04-21 19:55:33 +08:00
|
|
|
icons.Add(new GroupedDifficultyIcon(SetInfo.Beatmaps.FindAll(b => b.Ruleset.Equals(ruleset)), ruleset, this is ListBeatmapPanel ? Color4.White : colours.Gray5));
|
2019-08-24 04:40:41 +08:00
|
|
|
}
|
|
|
|
else
|
2019-11-11 19:53:22 +08:00
|
|
|
{
|
2019-08-24 04:40:41 +08:00
|
|
|
foreach (var b in SetInfo.Beatmaps.OrderBy(beatmap => beatmap.StarDifficulty))
|
|
|
|
icons.Add(new DifficultyIcon(b));
|
2019-11-11 19:53:22 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
return icons;
|
|
|
|
}
|
|
|
|
|
2018-05-29 06:31:20 +08:00
|
|
|
protected Drawable CreateBackground() => new UpdateableBeatmapSetCover
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2018-05-29 06:31:20 +08:00
|
|
|
BeatmapSet = SetInfo,
|
2018-04-13 17:19:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
public class Statistic : FillFlowContainer
|
|
|
|
{
|
|
|
|
private readonly SpriteText text;
|
|
|
|
|
|
|
|
private int value;
|
|
|
|
|
|
|
|
public int Value
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
get => value;
|
2018-04-13 17:19:50 +08:00
|
|
|
set
|
|
|
|
{
|
|
|
|
this.value = value;
|
|
|
|
text.Text = Value.ToString(@"N0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-27 18:29:27 +08:00
|
|
|
public Statistic(IconUsage icon, int value = 0)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.TopRight;
|
|
|
|
Origin = Anchor.TopRight;
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
Direction = FillDirection.Horizontal;
|
|
|
|
Spacing = new Vector2(5f, 0f);
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2019-02-12 12:04:46 +08:00
|
|
|
text = new OsuSpriteText { Font = OsuFont.GetFont(weight: FontWeight.SemiBold, italics: true) },
|
2018-04-13 17:19:50 +08:00
|
|
|
new SpriteIcon
|
|
|
|
{
|
2019-09-03 01:42:21 +08:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2018-04-13 17:19:50 +08:00
|
|
|
Icon = icon,
|
|
|
|
Shadow = true,
|
|
|
|
Size = new Vector2(14),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
Value = value;
|
|
|
|
}
|
|
|
|
}
|
2019-12-30 03:19:46 +08:00
|
|
|
|
|
|
|
public MenuItem[] ContextMenuItems => new MenuItem[]
|
|
|
|
{
|
|
|
|
new OsuMenuItem("View Beatmap", MenuItemType.Highlighted, ViewBeatmap),
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|