1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 10:23:21 +08:00
osu-lazer/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs

184 lines
7.7 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
2017-01-30 12:35:40 +08:00
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
2017-08-30 19:41:41 +08:00
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
2017-08-30 19:41:41 +08:00
using osu.Framework.Graphics.UserInterface;
2017-12-12 16:48:38 +08:00
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics.Sprites;
2017-08-30 19:41:41 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
2017-12-12 16:48:38 +08:00
using OpenTK;
using OpenTK.Graphics;
2017-12-12 16:48:38 +08:00
namespace osu.Game.Screens.Select.Carousel
2016-10-27 10:55:55 +08:00
{
2017-12-12 16:48:38 +08:00
public class DrawableCarouselBeatmapSet : DrawableCarouselItem, IHasContextMenu
{
2017-12-18 10:13:16 +08:00
private Action<BeatmapSetInfo> restoreHiddenRequested;
private Action<int> viewDetails;
private DialogOverlay dialogOverlay;
2017-12-12 16:48:38 +08:00
private readonly BeatmapSetInfo beatmapSet;
2017-12-12 16:48:38 +08:00
public DrawableCarouselBeatmapSet(CarouselBeatmapSet set)
: base(set)
{
2017-12-12 16:48:38 +08:00
beatmapSet = set.BeatmapSet;
}
[BackgroundDependencyLoader(true)]
private void load(LocalisationEngine localisation, BeatmapManager manager, BeatmapSetOverlay beatmapOverlay, DialogOverlay overlay)
{
if (localisation == null)
throw new ArgumentNullException(nameof(localisation));
2017-12-18 10:13:16 +08:00
restoreHiddenRequested = s => s.Beatmaps.ForEach(manager.Restore);
dialogOverlay = overlay;
if (beatmapOverlay != null)
viewDetails = beatmapOverlay.ShowBeatmapSet;
2017-12-13 11:46:02 +08:00
Children = new Drawable[]
{
new DelayedLoadWrapper(
2017-12-13 18:56:16 +08:00
new PanelBackground(manager.GetWorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault()))
{
2017-04-02 14:56:12 +08:00
RelativeSizeAxes = Axes.Both,
OnLoadComplete = d => d.FadeInFromZero(1000, Easing.OutQuint),
2017-12-13 11:46:02 +08:00
}, 300
),
2017-03-02 02:33:01 +08:00
new FillFlowContainer
{
2017-03-04 18:00:17 +08:00
Direction = FillDirection.Vertical,
Padding = new MarginPadding { Top = 5, Left = 18, Right = 10, Bottom = 10 },
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new OsuSpriteText
{
Font = @"Exo2.0-BoldItalic",
2017-12-12 16:48:38 +08:00
Current = localisation.GetUnicodePreference(beatmapSet.Metadata.TitleUnicode, beatmapSet.Metadata.Title),
TextSize = 22,
Shadow = true,
},
new OsuSpriteText
{
Font = @"Exo2.0-SemiBoldItalic",
2017-12-12 16:48:38 +08:00
Current = localisation.GetUnicodePreference(beatmapSet.Metadata.ArtistUnicode, beatmapSet.Metadata.Artist),
TextSize = 17,
Shadow = true,
},
2017-12-12 16:48:38 +08:00
new FillFlowContainer<FilterableDifficultyIcon>
{
Margin = new MarginPadding { Top = 5 },
AutoSizeAxes = Axes.Both,
Children = ((CarouselBeatmapSet)Item).Beatmaps.Select(b => new FilterableDifficultyIcon(b)).ToList()
}
}
}
};
}
2017-12-13 11:46:02 +08:00
public MenuItem[] ContextMenuItems
{
get
{
List<MenuItem> items = new List<MenuItem>();
if (Item.State == CarouselItemState.NotSelected)
items.Add(new OsuMenuItem("Expand", MenuItemType.Highlighted, () => Item.State.Value = CarouselItemState.Selected));
if (beatmapSet.OnlineBeatmapSetID != null)
items.Add(new OsuMenuItem("Details...", MenuItemType.Standard, () => viewDetails?.Invoke(beatmapSet.OnlineBeatmapSetID.Value)));
2017-12-13 11:46:02 +08:00
if (beatmapSet.Beatmaps.Any(b => b.Hidden))
2017-12-18 10:13:16 +08:00
items.Add(new OsuMenuItem("Restore all hidden", MenuItemType.Standard, () => restoreHiddenRequested?.Invoke(beatmapSet)));
2017-12-13 11:46:02 +08:00
2018-02-13 13:56:05 +08:00
items.Add(new OsuMenuItem("Delete", MenuItemType.Destructive, () => dialogOverlay?.Push(new BeatmapDeleteDialog(beatmapSet))));
2017-12-13 11:46:02 +08:00
return items.ToArray();
}
}
2017-03-07 09:59:19 +08:00
private class PanelBackground : BufferedContainer
{
public PanelBackground(WorkingBeatmap working)
{
CacheDrawnFrameBuffer = true;
2017-03-17 17:28:21 +08:00
Children = new Drawable[]
{
2017-03-17 17:28:21 +08:00
new BeatmapBackgroundSprite(working)
{
RelativeSizeAxes = Axes.Both,
2017-03-17 17:28:21 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fill,
},
2017-03-02 02:33:01 +08:00
new FillFlowContainer
{
2016-11-30 03:50:12 +08:00
Depth = -1,
2017-03-04 18:00:17 +08: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-12-13 11:46:02 +08:00
Colour = ColourInfo.GradientHorizontal(Color4.Black, new Color4(0f, 0f, 0f, 0.9f)),
Width = 0.05f,
},
new Box
{
RelativeSizeAxes = Axes.Both,
2017-12-13 11:46:02 +08: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-12-13 11:46:02 +08:00
Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.1f), new Color4(0, 0, 0, 0)),
Width = 0.05f,
},
}
},
};
}
}
2017-01-30 12:35:40 +08:00
public class FilterableDifficultyIcon : DifficultyIcon
{
private readonly BindableBool filtered = new BindableBool();
2017-12-12 16:48:38 +08:00
public FilterableDifficultyIcon(CarouselBeatmap item)
: base(item.Beatmap)
{
2017-12-12 16:48:38 +08:00
filtered.BindTo(item.Filtered);
filtered.ValueChanged += v => Schedule(() => this.FadeTo(v ? 0.1f : 1, 100));
filtered.TriggerChange();
}
}
2016-10-27 10:55:55 +08:00
}
}