osu/osu.Game/Beatmaps/Drawables/BeatmapSetHeader.cs

189 lines
7.2 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
2017-01-30 04:35:40 +00:00
using System.Collections.Generic;
using System.Linq;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
2017-08-30 11:41:41 +00:00
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Game.Graphics.Sprites;
using osu.Framework.Graphics.Shapes;
2017-08-30 11:41:41 +00:00
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;
2016-11-23 02:59:50 +00:00
namespace osu.Game.Beatmaps.Drawables
2016-10-27 02:55:55 +00:00
{
2017-08-30 11:41:41 +00:00
public class BeatmapSetHeader : Panel, IHasContextMenu
{
public Action<BeatmapSetHeader> GainedSelection;
2017-08-30 11:41:41 +00:00
public Action<BeatmapSetInfo> DeleteRequested;
2017-08-30 11:41:41 +00:00
public Action<BeatmapSetInfo> RestoreHiddenRequested;
private readonly SpriteText title;
private readonly SpriteText artist;
private readonly WorkingBeatmap beatmap;
private readonly FillFlowContainer difficultyIcons;
public BeatmapSetHeader(WorkingBeatmap beatmap)
{
if (beatmap == null)
throw new ArgumentNullException(nameof(beatmap));
this.beatmap = beatmap;
Children = new Drawable[]
{
new LoadWrapper(
2017-04-02 06:56:12 +00:00
new PanelBackground(beatmap)
{
2017-04-02 06:56:12 +00:00
RelativeSizeAxes = Axes.Both,
2017-07-22 18:50:25 +00:00
OnLoadComplete = d => d.FadeInFromZero(400, Easing.Out),
}
2017-04-02 06:56:12 +00:00
)
{
TimeBeforeLoad = 300,
},
2017-03-01 18:33:01 +00:00
new FillFlowContainer
{
2017-03-04 10:00:17 +00:00
Direction = FillDirection.Vertical,
Padding = new MarginPadding { Top = 5, Left = 18, Right = 10, Bottom = 10 },
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
title = new OsuSpriteText
{
Font = @"Exo2.0-BoldItalic",
TextSize = 22,
Shadow = true,
},
artist = new OsuSpriteText
{
Font = @"Exo2.0-SemiBoldItalic",
TextSize = 17,
Shadow = true,
},
2017-03-01 18:33:01 +00:00
difficultyIcons = new FillFlowContainer
{
Margin = new MarginPadding { Top = 5 },
AutoSizeAxes = Axes.Both,
}
}
}
};
}
protected override void Selected()
{
base.Selected();
GainedSelection?.Invoke(this);
}
[BackgroundDependencyLoader]
private void load(LocalisationEngine localisation)
{
if (localisation == null)
throw new ArgumentNullException(nameof(localisation));
2017-05-06 06:03:08 +00:00
title.Current = localisation.GetUnicodePreference(beatmap.Metadata.TitleUnicode, beatmap.Metadata.Title);
artist.Current = localisation.GetUnicodePreference(beatmap.Metadata.ArtistUnicode, beatmap.Metadata.Artist);
}
2017-03-07 01:59:19 +00:00
private class PanelBackground : BufferedContainer
{
public PanelBackground(WorkingBeatmap working)
{
CacheDrawnFrameBuffer = true;
2017-03-17 09:28:21 +00:00
Children = new Drawable[]
{
2017-03-17 09:28:21 +00:00
new BeatmapBackgroundSprite(working)
{
RelativeSizeAxes = Axes.Both,
2017-03-17 09:28:21 +00:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fill,
},
2017-03-01 18:33:01 +00:00
new FillFlowContainer
{
2016-11-29 19:50:12 +00:00
Depth = -1,
2017-03-04 10:00:17 +00:00
Direction = FillDirection.Horizontal,
RelativeSizeAxes = Axes.Both,
// This makes the gradient not be perfectly horizontal, but diagonal at a ~40° angle
Shear = new Vector2(0.8f, 0),
Alpha = 0.5f,
Children = new[]
{
// The left half with no gradient applied
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
Width = 0.4f,
},
// Piecewise-linear gradient with 3 segments to make it appear smoother
new Box
{
RelativeSizeAxes = Axes.Both,
2017-07-23 05:30:50 +00:00
Colour = ColourInfo.GradientHorizontal(
Color4.Black, new Color4(0f, 0f, 0f, 0.9f)),
Width = 0.05f,
},
new Box
{
RelativeSizeAxes = Axes.Both,
2017-07-23 05:30:50 +00:00
Colour = ColourInfo.GradientHorizontal(
new Color4(0f, 0f, 0f, 0.9f), new Color4(0f, 0f, 0f, 0.1f)),
Width = 0.2f,
},
new Box
{
RelativeSizeAxes = Axes.Both,
2017-07-23 05:30:50 +00:00
Colour = ColourInfo.GradientHorizontal(
new Color4(0f, 0f, 0f, 0.1f), new Color4(0, 0, 0, 0)),
Width = 0.05f,
},
}
},
};
}
}
2017-01-30 04:35:40 +00:00
public void AddDifficultyIcons(IEnumerable<BeatmapPanel> panels)
{
if (panels == null)
throw new ArgumentNullException(nameof(panels));
2017-01-30 04:35:40 +00:00
foreach (var p in panels)
difficultyIcons.Add(new DifficultyIcon(p.Beatmap));
}
2017-08-30 11:41:41 +00:00
public MenuItem[] ContextMenuItems
{
get
{
List<MenuItem> items = new List<MenuItem>();
if (State == PanelSelectedState.NotSelected)
items.Add(new OsuMenuItem("Expand", MenuItemType.Highlighted, () => State = PanelSelectedState.Selected));
if (beatmap.BeatmapSetInfo.Beatmaps.Any(b => b.Hidden))
items.Add(new OsuMenuItem("Restore all hidden", MenuItemType.Standard, () => RestoreHiddenRequested?.Invoke(beatmap.BeatmapSetInfo)));
items.Add(new OsuMenuItem("Delete", MenuItemType.Destructive, () => DeleteRequested?.Invoke(beatmap.BeatmapSetInfo)));
2017-08-30 11:41:41 +00:00
return items.ToArray();
}
}
2016-10-27 02:55:55 +00:00
}
}