mirror of
https://github.com/ppy/osu.git
synced 2024-11-12 01:07:25 +08:00
217 lines
10 KiB
C#
217 lines
10 KiB
C#
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
using OpenTK;
|
|
using OpenTK.Graphics;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Localisation;
|
|
using osu.Game.Graphics;
|
|
using osu.Game.Graphics.Sprites;
|
|
using osu.Framework.Graphics.Shapes;
|
|
using osu.Game.Beatmaps;
|
|
using osu.Framework.Input;
|
|
using osu.Framework.Audio;
|
|
using osu.Framework.Configuration;
|
|
|
|
namespace osu.Game.Overlays.Direct
|
|
{
|
|
public class DirectGridPanel : DirectPanel
|
|
{
|
|
private const float horizontal_padding = 10;
|
|
private const float vertical_padding = 5;
|
|
|
|
private FillFlowContainer bottomPanel;
|
|
private PlayButton playButton;
|
|
private Box progressBar;
|
|
|
|
protected override PlayButton PlayButton => playButton;
|
|
public override Bindable<bool> PreviewPlaying { get; } = new Bindable<bool>();
|
|
|
|
public DirectGridPanel(BeatmapSetInfo beatmap) : base(beatmap)
|
|
{
|
|
Height = 140 + vertical_padding; //full height of all the elements plus vertical padding (autosize uses the image)
|
|
}
|
|
|
|
protected override void LoadComplete()
|
|
{
|
|
base.LoadComplete();
|
|
bottomPanel.LayoutDuration = 200;
|
|
bottomPanel.LayoutEasing = Easing.Out;
|
|
bottomPanel.Origin = Anchor.BottomLeft;
|
|
}
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load(OsuColour colours, LocalisationEngine localisation)
|
|
{
|
|
Content.CornerRadius = 4;
|
|
|
|
AddRange(new Drawable[]
|
|
{
|
|
new Box
|
|
{
|
|
RelativeSizeAxes = Axes.Both,
|
|
Colour = Color4.Black.Opacity(0.5f),
|
|
},
|
|
bottomPanel = new FillFlowContainer
|
|
{
|
|
Anchor = Anchor.BottomLeft,
|
|
Origin = Anchor.TopLeft,
|
|
Direction = FillDirection.Vertical,
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
Spacing = new Vector2(0f, vertical_padding),
|
|
Children = new Drawable[]
|
|
{
|
|
new FillFlowContainer
|
|
{
|
|
AutoSizeAxes = Axes.Both,
|
|
Padding = new MarginPadding { Left = horizontal_padding, Right = horizontal_padding },
|
|
Direction = FillDirection.Vertical,
|
|
Children = new[]
|
|
{
|
|
new OsuSpriteText
|
|
{
|
|
Text = localisation.GetUnicodePreference(SetInfo.Metadata.TitleUnicode, SetInfo.Metadata.Title),
|
|
TextSize = 18,
|
|
Font = @"Exo2.0-BoldItalic",
|
|
},
|
|
new OsuSpriteText
|
|
{
|
|
Text = localisation.GetUnicodePreference(SetInfo.Metadata.ArtistUnicode, SetInfo.Metadata.Artist),
|
|
Font = @"Exo2.0-BoldItalic",
|
|
},
|
|
},
|
|
},
|
|
new Container
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
Children = new Drawable[]
|
|
{
|
|
new Box
|
|
{
|
|
RelativeSizeAxes = Axes.Both,
|
|
},
|
|
progressBar = new Box
|
|
{
|
|
Origin = Anchor.BottomLeft,
|
|
RelativeSizeAxes = Axes.X,
|
|
BypassAutoSizeAxes = Axes.Both,
|
|
Size = new Vector2(0, 3),
|
|
Alpha = 0,
|
|
Colour = colours.Yellow,
|
|
},
|
|
new FillFlowContainer
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
Direction = FillDirection.Vertical,
|
|
Padding = new MarginPadding
|
|
{
|
|
Top = vertical_padding,
|
|
Bottom = vertical_padding,
|
|
Left = horizontal_padding,
|
|
Right = horizontal_padding,
|
|
},
|
|
Children = new Drawable[]
|
|
{
|
|
new FillFlowContainer
|
|
{
|
|
AutoSizeAxes = Axes.Both,
|
|
Direction = FillDirection.Horizontal,
|
|
Children = new[]
|
|
{
|
|
new OsuSpriteText
|
|
{
|
|
Text = "mapped by ",
|
|
TextSize = 14,
|
|
Shadow = false,
|
|
Colour = colours.Gray5,
|
|
},
|
|
new OsuSpriteText
|
|
{
|
|
Text = SetInfo.Metadata.Author,
|
|
TextSize = 14,
|
|
Font = @"Exo2.0-SemiBoldItalic",
|
|
Shadow = false,
|
|
Colour = colours.BlueDark,
|
|
},
|
|
},
|
|
},
|
|
new Container
|
|
{
|
|
AutoSizeAxes = Axes.X,
|
|
Height = 14,
|
|
Children = new[]
|
|
{
|
|
new OsuSpriteText
|
|
{
|
|
Text = $"from {SetInfo.Metadata.Source}",
|
|
TextSize = 14,
|
|
Shadow = false,
|
|
Colour = colours.Gray5,
|
|
Alpha = string.IsNullOrEmpty(SetInfo.Metadata.Source) ? 0f : 1f,
|
|
},
|
|
},
|
|
},
|
|
new FillFlowContainer
|
|
{
|
|
AutoSizeAxes = Axes.X,
|
|
Height = 20,
|
|
Margin = new MarginPadding { Top = vertical_padding, Bottom = vertical_padding },
|
|
Children = GetDifficultyIcons(),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
new FillFlowContainer
|
|
{
|
|
Anchor = Anchor.TopRight,
|
|
Origin = Anchor.TopRight,
|
|
AutoSizeAxes = Axes.Both,
|
|
Direction = FillDirection.Vertical,
|
|
Margin = new MarginPadding { Top = vertical_padding, Right = vertical_padding },
|
|
Children = new[]
|
|
{
|
|
new Statistic(FontAwesome.fa_play_circle, SetInfo.OnlineInfo?.PlayCount ?? 0)
|
|
{
|
|
Margin = new MarginPadding { Right = 1 },
|
|
},
|
|
new Statistic(FontAwesome.fa_heart, SetInfo.OnlineInfo?.FavouriteCount ?? 0),
|
|
},
|
|
},
|
|
playButton = new PlayButton(PreviewPlaying)
|
|
{
|
|
Margin = new MarginPadding { Top = 5, Left = 10 },
|
|
Size = new Vector2(30),
|
|
Alpha = 0,
|
|
TrackURL = "https://b.ppy.sh/preview/" + SetInfo.OnlineBeatmapSetID + ".mp3",
|
|
},
|
|
});
|
|
|
|
PreviewPlaying.ValueChanged += newValue => playButton.FadeTo(newValue || IsHovered ? 1 : 0, 120, Easing.InOutQuint);
|
|
PreviewPlaying.ValueChanged += newValue => progressBar.FadeTo(newValue ? 1 : 0, 120, Easing.InOutQuint);
|
|
}
|
|
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
|
|
if (PreviewPlaying && playButton.Track != null)
|
|
progressBar.Width = (float)(playButton.Track.CurrentTime / playButton.Track.Length);
|
|
}
|
|
|
|
protected override bool OnClick(InputState state)
|
|
{
|
|
StartDownload();
|
|
return true;
|
|
}
|
|
}
|
|
}
|