1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-19 23:32:58 +08:00
osu-lazer/osu.Game/Overlays/Direct/DirectPanel.cs

215 lines
7.0 KiB
C#
Raw Normal View History

// 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;
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
namespace osu.Game.Overlays.Direct
{
2019-12-30 03:19:46 +08:00
public abstract class DirectPanel : 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;
public Bindable<bool> PreviewPlaying => PlayButton?.Playing;
2018-04-13 17:19:50 +08:00
protected abstract PlayButton PlayButton { get; }
protected abstract Box PreviewBar { get; }
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;
2018-04-13 17:19:50 +08:00
protected DirectPanel(BeatmapSetInfo setInfo)
{
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)]
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(),
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
{
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);
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);
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>();
if (SetInfo.Beatmaps.Count > maximum_difficulty_icons)
{
foreach (var ruleset in SetInfo.Beatmaps.Select(b => b.Ruleset).Distinct())
2019-08-25 10:44:56 +08:00
icons.Add(new GroupedDifficultyIcon(SetInfo.Beatmaps.FindAll(b => b.Ruleset.Equals(ruleset)), ruleset, this is DirectListPanel ? Color4.White : colours.Gray5));
}
else
2019-11-11 19:53:22 +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;
}
protected Drawable CreateBackground() => new UpdateableBeatmapSetCover
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.Both,
BeatmapSet = SetInfo,
2018-04-13 17:19:50 +08:00
};
public class Statistic : FillFlowContainer
{
private readonly SpriteText text;
private int value;
public int Value
{
get => value;
2018-04-13 17:19:50 +08:00
set
{
this.value = value;
text.Text = Value.ToString(@"N0");
}
}
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[]
{
text = new OsuSpriteText { Font = OsuFont.GetFont(weight: FontWeight.SemiBold, italics: true) },
2018-04-13 17:19:50 +08:00
new SpriteIcon
{
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
}
}